Re: g_spawn question



Thomas Vander Stichele <thomas urgent rug ac be> writes:

I have a question regarding the g_spawn functions in glib.  I'm writing an 
infra-red panel application using gnome2 libraries.

One of the things this app does is execute external helper shell scripts.  
These scripts output minimized information while they're running.  This 
output should then be captured by the panel app and displayed line by 
line.

Now, what I did was use g_spawn_async_with_pipes and connect a GIOChannel 
to the stdout of the spawned process.  This works; I can process the 
output of the spawned process line by line.

The problem starts when the spawned process is done running.  For some 
reason my app starts spinning idly, using 99.9% CPU.

Now, my suspicion is that when the spawned process stops, the 
corresponding iochannel of stdout isn't unreffed.  I'm not sure if this is 
the case or how to verify this; I can only tell from what I see and from 
my (maybe mistaken) interpretation of the glib source code.  But I suppose 
it might be likely that, for example, the file descriptor of the spawned 
stdout is closed, but the iochannel doesn't know.

So, my question is, does this make sense ? Is this the right behaviour ? 
Is there some way I can install a callback to be called when the spawned 
process stops ? How can I cleanly prevent my app from spinning idly, or 
otherwise debug the situation ?


Yes, I think you diagnosed this correctly. If you haven't figured it
out in the interval since you posted this mail (moderation queue was
lagging I guess), you need to remove your GIOChannel when the other
end of the pipe is closed. I think you get a G_IO_HUP condition when
this happens, IIRC.

Another option is to use G_SPAWN_DO_NOT_REAP_CHILD or whatever it's
called and then you get SIGCHLD when the child exits.

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]