Re: What's the difference between the UNIX signal and gtk signal?
- From: "Edward A. Falk" <falk efalk org>
- To: gtk-list gnome org
- Subject: Re: What's the difference between the UNIX signal and gtk signal?
- Date: Fri, 17 May 2002 08:16:40 -0700
> there is no relationship *whatsoever* between the two except the name.
Yes, in fact, AFAICT, gtk doesn't even provide a mechanism for handling
Unix signals. The best you can do is set up a traditional unix signal
handler which does nothing but catch the signal and write something to
a pipe, and write a gtk input handler for the other end of the pipe.
(You need to do this because it's not safe to call gtk functions from
within a unix signal handler.)
void sig_watcher(int) ;
void sig_catcher(gpointer, gint, GdkInputCondition) ;
int signal_fds ;
/* Set up to catch signals */
if( pipe(signal_fds) == 0 )
long arg ;
(void) signal(SIGIO, sig_watcher) ;
(void) signal(SIGUSR1, sig_watcher) ;
(void) signal(SIGCHLD, sig_watcher) ;
/* etc */
gdk_input_add( signal_fds, GDK_INPUT_READ, sig_catcher, NULL) ;
arg = fcntl(signal_fds, F_GETFL) ;
fcntl(signal_fds, F_SETFL, arg | O_NONBLOCK) ;
/* Catch unix signals, write them to the pipe */
write(signal_fds, &signum, sizeof(signum)) ;
/* Get signals from the pipe. *Now* it is safe to call gtk */
sig_catcher(gpointer d, gint fd, GdkInputCondition cond)
int signum ;
while( read(signal_fds, &signum, sizeof(signum)) > 0 )
printf("Look! caught signal %d\n", signum) ;
(This isn't 100% correct though, now that I think about it. The signal
watcher needs to use a non-blocking write in case the pipe ever fills up.
In that case, signals should be discarded. I'll work on it some more.)
] [Thread Prev