I'm trying to write a Task control program, very much like Supervisor.
I run some programs from a config file and let them run in the background, while in the main process I read and execute other commands.
Before fork()
-ing, in the main process I call:
sigaction(SIGINT, &the_handler, NULL);
Where the_handler
stores the reference of a simple print function.
When CTRL+C is pressed, the child processes are interrupted as well (which I don't want).
I could run: signal(SIGINT, SIG_IGN);
after fork in child process to ignore it, but I would like to still to be able to run this command in bash: $ kill -n 2 <child_pid>
, meaning, I don't want to ignore it, right?
So, how to ignore SIGINT from CTRL+C to child processes, but still be able to receive the signal in other ways? Or am I missing something?
setsid
ordaemon
– Enwind