Ignore SIGINT signal in child process

2019-04-21 09:56发布

问题:

I am writing a simple program in which parent and child process are alternatively printing into a file. I have managed to do this using user defined signals. Now I want to handle the SIGINT signal. Once ctrl-c is received the parent must send termination signal to child,the child should then should terminate and finally the parent should terminate.

My question is, in order to make this work properly I must catch the SIGINT signal ONLY from parent and IGNORE it from child. Is it right? If yes any hints on doing this?

回答1:

Call:

signal(SIGINT, SIG_IGN);

from the child process which will make the child process ignore the SIGINT signal. From man signal:

If the disposition is set to SIG_IGN, then the signal is ignored.



标签: c signals