In Unix-like operating systems, if a process\' pid
and its pgid
are equal, then the process is a process group leader.
However, if the proc
There is no succeeding leader: once a process group leader exits, the group loses leadership. Nothing requires a process group to have a leader, it's perfectly fine not to have one, and you can still send signals to every element in the group with kill(2)
.
What exactly happens when the leader exits depends on the status of the processes in the group and whether or not the group classifies as an orphaned process group.
First, let's see what is an orphaned group.
POSIX defines an orphaned process group as a group in which the parent of each process belonging to that group is either a member of that same group or is part of another session.
In other words, a process group is not orphaned as long as at least one process in the group has a parent in a different process group but in the same session.
This definition may seem odd at first, but there is a rationale behind this, which will (hopefully) be clear in a moment.
So why is it important to know if a group is orphaned? Because of processes that are stopped. If a process group is orphaned, and there is at least one process in that group that is stopped (e.g. it was suspended with SIGSTOP
or SIGTSTP
), then POSIX.1 requires that every process in the orphaned group be sent SIGHUP
followed by SIGCONT
. The reason for doing this is to avoid having the process stopped forever: consider the case where the session leader and the process group leader exit, and the group is left with a stopped process. Since the parent is in another session, it doesn't have permission to send it SIGCONT
, so the process would never run again.
OTOH, if the parent is in the same session but in a different group, then there is a chance that it will signal the stopped process with SIGCONT
, so the group is not considered orphaned and there is no need to forcefully wake up stopped processes.