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?

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.

  • 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 1: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 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.