Sessions and process groups in linux

Session: One or more process groups. Starts with user login and ends with user logout. All processes during this period belong to this session period.
Session head process: the process that calls setsid to create a session
1. It is stipulated that the group leader process cannot call setsid, because after calling setsid, the calling process will become the group leader process of the new process group.
How to ensure it? Call fork first, and then terminate the parent process. At this time, since the process group ID of the child process is the process group ID of the parent process, and the ID of the child process is reassigned, it is guaranteed that the child process will not be the process group leader, so the child process setsid can be called.
2. After calling setsid,
1) the calling process becomes the session head process
2) the calling process becomes the leader process of the new process group
3) deletes the controlling terminal
process group: one or more processes.
Group leader process: Process ID == Process group ID
Calling setpgid and setsid will create a process group.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327098456&siteId=291194637