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