Linux Signals – Can Ctrl+C Send SIGINT to Multiple Processes?

linuxprocess-groupssignals

I have read that when you press Ctrl+C a SIGINT signal will be sent to the foreground process group.

Can you give me an example of how I can have two or more processes in the foreground process group, because I want to see if all processes will terminate if I press Ctrl+C.

Best Answer

Since new processes all belong to the same process group, that of the parent process, have a process start a bunch of processes (fork), and then with appropriate logging and a delay, type Ctrl+C. They all eat a SIGINT.

$ perl -E 'fork for 1..2;say "ima $$"; $SIG{INT}=sub{die "woe $$\n"}; sleep 999'
ima 80920
ima 80922
ima 80921
ima 80923
^Cwoe 80920
woe 80922
woe 80921
woe 80923
$ 

(Add strace or sysdig or such to see the system calls or signals involved.)

Related Question