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 process leader has exited and the other processes in the same group are still running, who is the succeeding leader process?
The process group leader is the first member of the process group. It may terminate before the others, and then the process group is without leader. A process group is called orphaned when the parent of every member is either in the process group or outside the session.
In process groups, 5-10 individuals meet face to face to share their struggles and concerns with 1-2 trained group therapists. The power of process groups lies in the unique opportunity to receive multiple perspectives, support, encouragement and feedback from other individuals in safe and confidential environment.
The group of processes in a process group is sometimes referred to as a job and is manipulated as a single entity by processes such as the shell. Some signals (e.g., SIGINT) are delivered to all members of a process group, causing the group as a whole to suspend or resume execution, or to be interrupted or terminated.
Instituting this process group means that you keep an eye on the project's constraints throughout the Planning and Execution, and ensure that you're still on budget, on time, and within scope. There is flexibility in workflows, such that some might need more Planning, Execution, Monitoring and Controlling iterations.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With