One example:
bash-4.3$ ( ( sleep 2 & (ps -Hfj | sh -c cat; perl -MPOSIX -E 'say tcgetpgrp 0'; sleep 5;:);:);:)
UID PID PPID PGID SID C STIME TTY TIME CMD
chazelas 18631 3848 18631 18631 0 12:51 pts/7 00:00:00 /bin/zsh
chazelas 2184 18631 2184 18631 0 21:00 pts/7 00:00:00 bash --norc
chazelas 2430 2184 2430 18631 0 21:07 pts/7 00:00:00 bash --norc
chazelas 2431 2430 2430 18631 0 21:07 pts/7 00:00:00 bash --norc
chazelas 2432 2431 2430 18631 0 21:07 pts/7 00:00:00 sleep 2
chazelas 2433 2431 2430 18631 0 21:07 pts/7 00:00:00 bash --norc
chazelas 2434 2433 2430 18631 0 21:07 pts/7 00:00:00 ps -Hfj
chazelas 2435 2433 2430 18631 0 21:07 pts/7 00:00:00 sh -c cat
chazelas 2436 2435 2430 18631 0 21:07 pts/7 00:00:00 cat
2430
At the time ps
was running, there were 7 processes in the 2430 process group: 3 subshell processes (bash
), one running ps
, one running sh
, one running cat
, one running sleep 1
. Later on, the processes spawned to execute perl
and sleep 5
would also be in that same group.
tcgetpgrp()
confirms that 2430 was indeed the foreground process group of the terminal device, so upon pressing Ctrl+C, all the processes in that group would receive a SIGINT.