ynn
ynn

Reputation: 4857

Can parent shell be considered background process group in the context of Linux session?

I opened a terminal and executed the following commands:

$ sleep 100000 &
$ sleep 100000 &
$ bash -c '{ sleep 100000 & } && cat && sleep 500000'

Now I have this process tree:

    SID    PGRP     PID Command
-------------------------------------------------------------
 496410  496410  496410  -bash
 496410  496427  496427   ├─ sleep 100000
 496410  496430  496430   ├─ sleep 100000
 496410  500081  500081   └─ bash -c { sleep 100000 & } && cat && sleep 500000
 496410  500081  500082      ├─ sleep 100000
 496410  500081  500083      └─ cat

From this tree, we can see

I have two questions:


Terminology used in the OP: POSIX

Upvotes: 0

Views: 24

Answers (1)

ynn
ynn

Reputation: 4857

The POSIX's terminology mentioned in the OP is abstract and hard to read. Instead you may want to refer to man 7 credentials.


As for the questions in the OP:

A session can have at most 1 foreground process group. In the process tree above, it is the process group 500081 bash -c { sleep 100000 & } && cat && sleep 500000, right?

Yes.

The process groups 496427 sleep 100000 and 496430 sleep 100000 are clearly background process groups, but is the session leader 496410 -bash also considered a member of the background process group (496410)?

Yes.

These can be confirmed just by enabling TPGID (Process ID of the fg process group of the controlling terminal) column in htop:

    SID    PGRP     PID  TPGID  Command
-------------------------------------------------------------
 496410  496410  496410  500081  -bash
 496410  496427  496427  500081   ├─ sleep 100000
 496410  496430  496430  500081   ├─ sleep 100000
 496410  500081  500081  500081   └─ bash -c { sleep 100000 & } && cat && sleep 500000
 496410  500081  500082  500081      ├─ sleep 100000
 496410  500081  500083  500081      └─ cat

Upvotes: 0

Related Questions