From The Linux Programming Interface
#include <unistd.h> int setpgid(pid_t pid , pid_t pgid );
The pid argument may not specify a process that is a session leader. Violation of this rule results in the error EPERM .
- Why can't
pid
be a session leader? Can
pid
be a group leader and why?If yes, after the call to
setpgid()
, in which group will the other processes originally in the group originally led by processpid
be:- the original group whose gid is
pid
which now has lost processpid
and has no group leader, or - the new group
pgid
which processpid
is changed to?
I suspect the first might contradict to what the book described for
setsid()
:The restriction against a process group leader being able to call setsid() is necessary because, without it, the process group leader would be able to place itself in another (new) session, while other members of the process group remained in the original session. (A new process group would not be created, since, by definition, the process group leader’s process group ID is already the same as its process ID.) This would violate the strict two-level hierarchy of sessions and process groups, whereby all members of a process group must be part of the same session.
- the original group whose gid is
Thanks.
Some related questions Can a leader of a process session or group leave for another existing session or group?