Ignore SIGINT signal in child process

2019-04-21 09:28发布

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?

标签: c signals
1条回答
太酷不给撩
2楼-- · 2019-04-21 10:00

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.

查看更多
登录 后发表回答