Must every process group belong to one process session

processprocess-groupssession

  1. Must every process group belong to one process session? In other
    words, is process group a concept which exists only within a process
    session?

    Is there a process group which doesn't belong to any process session? Can a process group not have a session id?

  2. When a process group has been disowned from a bash shell by the
    builtin command disown,

    • does the process group still exist?

    • do the
      processes originally in the process group still have the same group
      id, implying that they still form a process group?

Best Answer

POSIX defines sessions thus:

A collection of process groups established for job control purposes. Each process group is a member of a session. A process is considered to be a member of the session of which its process group is a member. A newly created process joins the session of its creator. A process can alter its session membership; see setsid(). There can be multiple process groups in the same session.

All process groups belong to a session. The concepts aren't dependent though, so I wouldn't say that a process group is a concept which exists only within a session.

Background processes are given their own process group when they're created, so disowning them doesn't change their process group; disown only manipulates Bash's job table:

disown [-ar] [-h] [jobspec ...]

Without options, remove each jobspec from the table of active jobs. If jobspec is not present, and neither the -a nor the -r option is supplied, the current job is used. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.