僵尸进程在其父母去世后会去哪里? [英] Where do Zombie processes go after their parent dies?

查看:95
本文介绍了僵尸进程在其父母去世后会去哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Zombie进程是已完成执行但在进程表中仍具有一个条目的进程(父进程尚未读取其退出代码,或换句话说,它尚未获得").

A Zombie process is a process that has completed execution, but still has an entry in the process table (the parent hasn't read its exit code, or in other words, it hasn't been "reaped").

孤儿"进程是一个父进程已完成的进程,尽管它本身仍在运行(其父进程已逝世",但仍处于活动状态").在这种情况下,init将采用它并等待它.

An Orphan process is a process whose parent has finished, though it remains running itself (its parent has "passed away" but it is still "alive"). in this case, init will adopt it and will wait for it.

因此,请考虑以下问题:

So consider this:

int main(int argv, char *argc[]) {

    pid_t p=fork();

    if (p<0) {
        perror("fork");
    }

    // child
    if (p==0) {
        exit(2);
    }

    // parent sleeps for 2 seconds
    sleep(2);
    return 1;
}

此处创建的子进程将成为僵尸,持续2秒,但是当父进程完成后,其状态将如何?孤儿僵尸?

The child process being created here will be a zombie for 2 seconds, but what will be its status when the parent finishes? Orphan-zombie?

在进程表中其条目会发生什么?

What happens to its entry in the process table?

init还会采用孤儿僵尸"(例如上述)吗?

Are "orphan-zombies" (such as the above) also adopted by init and being reaped by it?

推荐答案

根据 man 2 wait :

终止但尚未等待的孩子成为 僵尸".内核会保留有关以下内容的最少信息: 僵尸进程(PID,终止状态,资源使用信息) 为了让父母以后可以进行等待以获得 有关孩子的信息.只要不将僵尸从 通过等待系统,它将占用内核进程中的一个插槽 表格,如果该表格已满,将无法创建 进一步的过程. 如果父进程终止,则其僵尸" 子代(如果有的话)被init(8)采纳,它会自动执行 等待删除僵尸.

A child that terminates, but has not been waited for becomes a "zombie". The kernel maintains a minimal set of information about the zombie process (PID, termination status, resource usage information) in order to allow the parent to later perform a wait to obtain information about the child. As long as a zombie is not removed from the system via a wait, it will consume a slot in the kernel process table, and if this table fills, it will not be possible to create further processes. If a parent process terminates, then its "zombie" children (if any) are adopted by init(8), which automatically performs a wait to remove the zombies.

父进程完成后,init将采用子进程(即使它是僵尸进程).然后,如您所说,initwait()表示退出状态.

When the parent process finishes, the child process (even if it's a zombie process) will be adopted by init. Then, as you said, init will wait() for its exit status.

所以,我认为孤儿僵尸"不是什么特例.

So, I don't think "orphan zombie" to be any special case.

这篇关于僵尸进程在其父母去世后会去哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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