Unix中会话和进程组的用途和含义? [英] Use and meaning of session and process group in Unix?

查看:48
本文介绍了Unix中会话和进程组的用途和含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unix 进程有一个会话 id 并且是进程组的一部分 - 可以使用 setsid()/getpgrp() 等函数更改/查询.

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 process group and session always eluded me, could anybody explain what significance having distinct sessions and process groups provide - why/when do one want to create a new session or place several processes in the same session and/or process group ?

推荐答案

进程组 是相关进程的集合,可以同时发出信号.

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.)

例如如果您从 shell 运行 some_app,shell 会为其创建一个新进程组,并使其成为会话的前台进程组.(some_app 可能会创建一些子进程;默认情况下,它们将属于同一个进程组.)如果然后按 ^Zsome_app的进程组收到信号以停止它;并且shell的进程组再次切换为前台进程组.然后例如 bg %1 将再次启动 some_app 的进程组,但保持它在后台运行.

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.

POSIX.1-2008 标准 相当易读(至少,我认为是这样)!) - 查看定义和相关部分通用终端接口"一章.

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.

这篇关于Unix中会话和进程组的用途和含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆