2

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

Now the accepted answer in this question says:

Basically, your signal is received by all foreground processes, ie the shell and the program,

I have executed cat within bash, and noticed that the PGID for bash and cat are different, so they do not belong to the same process group.

So when you press Ctrl+C, only cat will receive the SIGINT signal (and so the answer I quoted is wrong), am I correct?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Steve
  • 777
  • 1
  • 7
  • 15

1 Answers1

2

That question is about a bash script. You're running bash interactively. This makes a difference for process groups: that's the whole reason why process groups were invented. The intent of a process group is to capture all the processes that are involved in one interactively-started task. So an interactive shell starts each job in a separate process group, whereas a shell running a script doesn't create new process groups.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • Is the process group identified by the PID of the interactive shell? in other words if `echo $$` returned `432`, would `432` be the identifier for the process group also? – the_velour_fog May 18 '17 at 01:21
  • No, the process group of a job is the PID of the first process in that job. This cannot be the `$$` since it's the original shell process and different processes must have different PIDs. – Gilles 'SO- stop being evil' May 18 '17 at 01:24