流程组必须有运行中的领导者流程吗? [英] Must a process group have a running leader process?

查看:85
本文介绍了流程组必须有运行中的领导者流程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在类似Unix的操作系统中,如果进程的pid及其pgid相等,则该进程是进程组负责人.

In Unix-like operating systems, if a process' pid and its pgid are equal, then the process is a process group leader.

但是,如果流程负责人已经退出,并且同一组中的其他流程仍在运行,那么谁是后续的负责人流程?

However, if the process leader has exited and the other processes in the same group are still running, who is the succeeding leader process?

推荐答案

没有继任的领导者:一旦流程组负责人退出,该组就会失去领导权.不需要进程组拥有一个领导者,没有一个领导者也很好,并且您仍然可以使用kill(2)向该组中的每个元素发送信号.

There is no succeeding leader: once a process group leader exits, the group loses leadership. Nothing requires a process group to have a leader, it's perfectly fine not to have one, and you can still send signals to every element in the group with kill(2).

领导者退出时究竟发生了什么,取决于组中进程的状态以及该组是否归类为孤立进程组.

What exactly happens when the leader exits depends on the status of the processes in the group and whether or not the group classifies as an orphaned process group.

首先,让我们看看什么是孤立组.

First, let's see what is an orphaned group.

POSIX将孤立进程组定义为一个组,其中属于该组的每个进程的父级要么是同一组的成员,要么是另一个会话的一部分.

POSIX defines an orphaned process group as a group in which the parent of each process belonging to that group is either a member of that same group or is part of another session.

换句话说,只要组中的至少一个进程在另一个进程组中但是在同一会话中具有父级,就不会孤立该进程组.

In other words, a process group is not orphaned as long as at least one process in the group has a parent in a different process group but in the same session.

乍一看,这个定义可能看起来很奇怪,但是背后有一个基本原理,(希望)稍后会清楚.

This definition may seem odd at first, but there is a rationale behind this, which will (hopefully) be clear in a moment.

那么,为什么要弄清一个孤儿群体为什么很重要?由于进程已停止.如果一个进程组是孤立的,并且该组中至少有一个进程已停止(例如,它已被SIGSTOPSIGTSTP挂起),则POSIX.1要求发送孤立组中的每个进程SIGHUP后跟SIGCONT.这样做的原因是避免使进程永远停止:考虑会话负责人和进程组负责人退出,而该组留有停止的进程的情况.由于父级正在另一个会话中,因此它无权发送SIGCONT,因此该过程将永远不会再次运行.

So why is it important to know if a group is orphaned? Because of processes that are stopped. If a process group is orphaned, and there is at least one process in that group that is stopped (e.g. it was suspended with SIGSTOP or SIGTSTP), then POSIX.1 requires that every process in the orphaned group be sent SIGHUP followed by SIGCONT. The reason for doing this is to avoid having the process stopped forever: consider the case where the session leader and the process group leader exit, and the group is left with a stopped process. Since the parent is in another session, it doesn't have permission to send it SIGCONT, so the process would never run again.

OTOH,如果父级在同一会话中但在另一个组中,则很有可能会通过SIGCONT发出已停止进程的信号,因此该组不会被视为孤立的,因此无需强行使用唤醒停止的进程.

OTOH, if the parent is in the same session but in a different group, then there is a chance that it will signal the stopped process with SIGCONT, so the group is not considered orphaned and there is no need to forcefully wake up stopped processes.

这篇关于流程组必须有运行中的领导者流程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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