Re: [gtk-list] Forking




On Sat, 19 Dec 1998 lev@mindless.com wrote:
> 
> I am writeing a program and I want some operation to be per performed w/o
> stopping gtk (network talk). I fork the program and the child sends
> signals to notify the parent. Now the qestion is, is it ok to call gtk
> functions from signal handler? Signal may be called while gtk_main is
> doing what ever it was to do. Is it bad to interrupt it and do other
> gtk stuff? Is there a better way to organize this?
> 

I think it's generally considered a bad idea to do anything substantial in
signal handlers; the problem is that they can interrupt any function at
any time, so it's hard to know whether you have a sane state or not. 

Two better solutions:

 - In the signal handler, just set some kind of flag; then at some 
   appropriate time in the normal course of your program, check the flag. 
   You could maybe check the flag periodically in a timeout, or something
   like that. 

 - Use pipes instead of signals to communicate between processes; 
   you can use gtk_input_add() to have the event loop monitor a pipe and 
   call your callback if there's any activity. This can be very simple; 
   just create a pipe with pipe(), fork, and whenever you want the 
   parent to listen to the child send a byte of data across the 
   pipe to trigger your callback.

HTH,
Havoc




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