3
  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?

Tim
  • 101,790
  • Related questions: https://unix.stackexchange.com/questions/405755/ and https://unix.stackexchange.com/questions/404054/ – JdeBP Nov 20 '17 at 16:20

1 Answers1

3

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.

Stephen Kitt
  • 434,908
  • Thanks. what are the relation and difference between active jobs and process groups? What does a job being active or not mean? Is an inactive job in a bash shell still a process group in the shell's session? – Tim Dec 20 '16 at 08:35
  • I'd forgotten your habit of asking follow-up questions ;-). A process group is a system concept, a job is a shell concept. As mentioned before, each background process is placed in a new process group, which means that each job is in its own process group. The processes in a job share the shell's session, even when their job is disowned. – Stephen Kitt Dec 20 '16 at 08:51
  • "The processes in a job share the shell's session, even when their job is disowned". Then what does disown do? Since disown removes a job from the table of active jobs, what do an active job and inactive job mean? A disowned job is still running, so an inactive job can't mean a suspended job. – Tim Dec 20 '16 at 14:00
  • As I understand it, an inactive job is a job which is no longer tracked by the shell, either because it's finished, or because it's been disowned. Removing a job from the table of active jobs makes it inactive (without suspending the process or anything like that). Perhaps thinking of "active" as meaning "part of the shell's signal chain" would help. – Stephen Kitt Dec 20 '16 at 14:27
  • Inactive job and background job are different concepts, correct? 2) " if the -h option is given, each jobspec is not removed from the table of active jobs, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. ". So is "active" implied by "part of the shell's signal chain" , but not the other way around?
  • – Tim Dec 20 '16 at 14:33
  • I highly recommend you read the job control section of the Bash manual. The documentation only mentions "active jobs", it never defines "inactive jobs"; "active jobs" are literally "jobs present in the table of active jobs", so "inactive jobs" are "jobs absent from the table of active jobs". My analogy was an approximation. – Stephen Kitt Dec 20 '16 at 14:46