Process Groups vs Job Control – Key Differences

job-controlprocessprocess-groups

What's the difference between a process group and a job? If I type pr * | lpr then is it both a process group as well a job?
What exactly is the difference between a process group ID and a job ID?

Edit: I know it appears similar to What is the difference between a job and a process?, but it is slightly different. Also, I didn't understand this concept from this thread.

Best Answer

A process group is a unix kernel concept. It doesn't come up very often. You can send a signal to all the processes in a group, by calling the kill system call or utility with a negative argument.

When a process is created (with fork), it remains in the same process group as its parent. A process can move into another group by calling setpgid or setpgrp. This is normally performed by the shell when it starts an external process, before it executes execve to load the external program.

The main use for process groups is that when you press Ctrl+C, Ctrl+Z or Ctrl+\ to kill or suspend programs in a terminal, the terminal sends a signal to a whole process group, the foreground process group. The details are fairly complex and mostly of interest to shell or kernel implementers; the General Terminal Interface chapter of the POSIX standard is a good presentation (you do need some unix programming background).

Jobs are an internal concept to the shell. In the simple cases, each job in a shell corresponds to a process group in the kernel.