clinuxposixjob-controlprocess-group

Does Linux allow process group ids to be reassigned to processes?


Suppose pid X is a process group leader and X terminates, but other processes in the process group remain running (with X as their pgid). Will Linux prevent the value X from being assigned as a pid to a new process?

I ask this because of a failure condition POSIX allows for setsid:

[EPERM] The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process.

This error seems to be an unrecoverable condition for code using process groups (i.e. shells) that would be triggered "at random", making it even more odious. I would assume any implementation aiming at sane levels of quality would avoid reassigning X as a pid while it's still in use as a pgid, but I can't find this documented anywhere.


Solution

  • Not a problem, because fork guarantees:

    The child process ID also shall not match any active process group ID.

    And fork is the only way to create new processes.