Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 1.42 KB

process-session-process-group-thread-group.md

File metadata and controls

25 lines (18 loc) · 1.42 KB

Relationship between processes, Session, process group and thread group

Kernel use this information for delivering signals to a collection of processes/threads.

When a process is created, it inherits group id of its parent. It can later change its group or create new group and becomes the group leader by calling setpgid. The group leader’s group id equals its pid.

kill(pid_t pid, int sig) with negative pid will send signal to all members of group -pid. Similarly waitpid with negative pid wil wait for any member of group -pid.

Each group belong to a unique session. First process of a session (also group leader) is the session leader, its pid equals session id. The session can be changed by calling setsid but is usually called in login process. Session has controlling tty (/dev/tty), signals generated by CTRL-C/Z are delivered to these processes of the foreground group of that session.

When a process is created, its ordinary thread id equals process id. When additional thread is created with CLONE_THREAD it has different thread id but same process id, which is called thread group id. The gettid returns thread id while getpid returns thread group id. tkill is used to send signal to a thread.

References

  1. http://www.win.tue.nl/~aeb/linux/lk/lk-10.html#ss10.2
  2. http://linux.die.net/man/2/kill
  3. http://linux.die.net/man/2/waitpid
  4. http://linux.die.net/man/2/clone