为什么 fork() 两次 [英] Why fork() twice

查看:42
本文介绍了为什么 fork() 两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Nagios 允许我配置 child_processes_fork_twice=<0/1>.

Nagios lets me configure child_processes_fork_twice=<0/1>.

文档

这个选项决定了 Nagios 在执行主机和服务检查时是否会 fork() 子进程两次.默认情况下,Nagios fork() 两次.但是,如果启用了 use_large_installation_tweaks 选项,它只会 fork() 一次.

This option determines whether or not Nagios will fork() child processes twice when it executes host and service checks. By default, Nagios fork()s twice. However, if the use_large_installation_tweaks option is enabled, it will only fork() once.

据我所知 fork() 会产生一个新的子进程.为什么我要这样做两次?

As far as I know fork() will spawn a new child process. Why would I want to do that twice?

推荐答案

在 Linux 中,守护进程通常是通过 fork 两次创建的,中间进程在 fork 孙子进程后退出.这具有孤立孙子进程的效果.因此,如果它终止,则操作系统有责任在它之后进行清理.原因与所谓的僵尸进程有关,它们在退出后继续存活并消耗资源,因为通常负责清理的父进程也已经死亡.

In Linux, a daemon is typically created by forking twice with the intermediate process exiting after forking the grandchild. This has the effect of orphaning the grandchild process. As a result, it becomes the responsibility of the OS to clean up after it if it terminates. The reason has to do with what are known as zombie processes which continue to live and consume resources after exiting because their parent, who'd normally be responsible for the cleaning up, has also died.

这篇关于为什么 fork() 两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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