Use and meaning of session and process group in Unix?

前端 未结 2 630
我在风中等你
我在风中等你 2020-12-07 08:45

Unix processes have a session id and are part of a process group - which can be changed/queried with functions such as setsid()/getpgrp() .

However the concept of a

2条回答
  •  盖世英雄少女心
    2020-12-07 09:33

    A process group is a collection of related processes which can all be signalled at once.

    A session is a collection of process groups, which are either attached to a single terminal device (known as the controlling terminal) or not attached to any terminal.

    Sessions are used for job control: one of the process groups in the session is the foreground process group, and can be sent signals by terminal control characters. You can think of a session with a controlling terminal as corresponding to a "login" on that terminal. (Daemons normally disassociate themselves from any controlling terminal by creating a new session without one.)

    e.g. if you run some_app from the shell, the shell creates a new process group for it, and makes that the foreground process group of the session. (some_app might create some child processes; by default they will be part of the same process group.) If you then press ^Z, some_app's process group is signalled to stop it; and the shell's process group is switched to be the foreground process group again. Then e.g.bg %1 would start some_app's process group again, but keep it running in the background.


    The POSIX.1-2008 standard is fairly readable (at least, I think so!) - take a look at the definitions and the relevant sections of the "General Terminal Interface" chapter.

提交回复
热议问题