In my program, I fork() several times depending on user input.
In certain instances, I want to handle SIGCHLD and say something like ‘Process # Finished’. In other cases though, I want to ignore this signal.
How can I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Signal handling is set up globally for the process. If you want to catch an asynchronous signal like SIGCHLD when some children terminate but not others, you can’t decide to ignore it for some in advance.
You will need to handle the signal every time in the parent, then decide whether you want to ignore it in your handler.
At minimum, your handler should do a wait() on the child (si_pid in the siginfo_t structure) to harvest its return code. At that point you can check the process id and decide what else to do. You don’t have to print anything if you don’t want to.