Search code examples
csignals

Ignore SIGINT signal in child process


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?


Solution

  • 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.