1

Why is it that a Process Group Leader can't change its PGID? I know it sounds dumb for a leader to just abandon its own group, but what is the actual architectural reason behind this? What would actually break in the kernel or the process hierarchy if a leader was allowed to hop into another group?

New contributor
Bhushitha Hashan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

3

A Process Group Leader cannot change its PGID because the leader's PID is the group's unique identifier.

If a leader moved to a different group, the remaining processes in the original group would become "headless." The other processes are still pointing to the old group leader's PID. This would break the kernel's internal logic in three specific ways:

  1. If the leader leaves and eventually dies, its PID could be reused by a new process. The kernel would then have no way to distinguish between the "old" process group and the "new" process (the leader's PID is the process group).

  2. Process groups are anchored to the leader for job control. Without a leader, the shell loses its association to send signals (like SIGINT) to the entire group.

  3. The TTY tracks the foreground process group by its PGID. If the leader gives up that role, the terminal is left pointing to a group identity that no longer matches an active leader, causing job control to collapse.

The leader doesn't just manage the group; the leader defines the group.

3
  • Point 1 begs the question: What happens when the leader terminates and is collected? Can it's process id be reused? Does it hang in a zombie-like state white there are processes in its process group? Do all the processes in its process group get mysteriously killed? (Linux man pages talk about orphaned process groups, but only about what happens if a process in the process group is suspended.) Commented 8 hours ago
  • @DavidG. It cant be reused as theres ref count field in pid struct.until ref count hit zero its not going to be used right?as the pgid members also considered as references? Commented 7 hours ago
  • @Andy Dalton. But still pid cant be used until there are refs to it right?and signals are delevered via shells foreground process group since the rest of the members are still there its doable unless leader is the only process in the group senario? Commented 7 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.