By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,376 Members | 1,559 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,376 IT Pros & Developers. It's quick & easy.

handle signals in c

P: 18
i what to knew what is the meaning of the next instructions:
signal(SIGCHLD, catch_term);

void catch_term (int sig) /* if we receive a SIGCHLD ... */
{
signal (sig, catch_term);
}

i knew that the function signal catch the SIGCHLD signal and then calls the catch_therm function. I don't understand why the catch_term function calls again the signal function, i research this problem and i found that the signal called in the catch_term reset in some way the signal but it is not very clear for me what is actually happen, this is the thing that i want to clarify. And another question why the function isn't become a recursive one.
thx
Jun 1 '07 #1
Share this Question
Share on Google+
1 Reply


100+
P: 256
i what to knew what is the meaning of the next instructions:
signal(SIGCHLD, catch_term);

void catch_term (int sig) /* if we receive a SIGCHLD ... */
{
signal (sig, catch_term);
}

i knew that the function signal catch the SIGCHLD signal and then calls the catch_therm function. I don't understand why the catch_term function calls again the signal function, i research this problem and i found that the signal called in the catch_term reset in some way the signal but it is not very clear for me what is actually happen, this is the thing that i want to clarify. And another question why the function isn't become a recursive one.
thx
Its registering as the signal handler again so that next time the SIGCHLD signal comes up catch_term() will be exected. I'm not sure if the signal handler for a given signal is cleared each time the signal is caught, but this code assumes that is the case (which may be correct).
Jun 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.