nohup和守护程序之间有什么区别? [英] What's the difference between nohup and a daemon?

查看:103
本文介绍了nohup和守护程序之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将脚本作为守护程序运行而不是使用nohup有什么含义?

What are the implications of running a script as a daemon versus using nohup?

我知道分叉过程等有什么区别,但是有什么影响

I know what the difference is in terms of forking processes etc., but what impact does that have on my script?

推荐答案

nohup 命令是可怜的人作为守护进程运行进程的方式。正如Bruno Ranschaert指出的那样,当您在交互式外壳中运行命令时,它具有控制终端,并且在控制过程(通常是登录外壳)退出时将收到SIGHUP(挂断)信号。 nohup 命令安排输入来自 / dev / null ,输出和错误都进入 nohup.out ,使程序忽略中断,退出信号和挂断。实际上,它仍然具有相同的控制终端-它只是忽略了终端控制。请注意,如果您希望进程在后台运行,则必须告诉Shell在后台运行-至少在Solaris上(即,键入' nohup sleep 20& ';在没有&符的情况下,该过程在前台同步运行。

The nohup command is the poor man's way of running a process as a daemon. As Bruno Ranschaert noted, when you run a command in an interactive shell, it has a controlling terminal and will receive a SIGHUP (hangup) signal when the controlling process (typically your login shell) exits. The nohup command arranges for input to come from /dev/null, and for both output and errors to go to nohup.out, and for the program to ignore interrupts, quit signals, and hangups. It actually still has the same controlling terminal - it just ignores the terminals controls. Note that if you want the process to run in the background, you have to tell the shell to run it in the background - at least on Solaris (that is, you type 'nohup sleep 20 &'; without the ampersand, the process runs synchronously in the foreground).

通常,一个过程通过 nohup 需要花费一些时间,但不会闲逛等待来自其他地方的交互。

Typically, a process run via nohup is something that takes time, but which does not hang around waiting for interaction from elsewhere.

通常(这意味着如果您努力尝试,您会发现这些规则的例外),守护进程是潜伏在后台,与任何终端断开连接但等待响应某种输入的进程。网络守护程序等待连接请求或UDP消息通过网络到达,执行适当的工作并再次发送回响应。例如,使用Web服务器或DBMS。

Typically (which means if you try hard, you can find exceptions to these rules), a daemon process is something which lurks in the background, disconnected from any terminal, but waiting to respond to some input of some sort. Network daemons wait for connection requests or UDP messages to arrive over the network, do the appropriate work and send a response back again. Think of a web server, for example, or a DBMS.

当进程完全自我守护时,它会执行的某些步骤。 nohup 代码通过;它会重新安排其I / O,使其不连接到任何终端,将其自身与进程组分离,并忽略适当的信号(这可能意味着它不会忽略任何信号,因为没有终端可以将生成的任何信号发送给它通过终端)。通常,它分叉一次,并且父级成功退出。子进程通常在修复其进程组和会话ID等之后再次进行分叉;然后孩子也退出。孙子过程现在是自主的,不会在启动该终端的终端的 ps 输出中显示。

When a process fully daemonizes itself, it goes through some of the steps that the nohup code goes through; it rearranges its I/O so it is not connected to any terminal, detaches itself from the process group, ignores appropriate signals (which might mean it doesn't ignore any signals, since there is no terminal to send it any of the signals generated via a terminal). Typically, it forks once, and the parent exits successfully. The child process usually forks a second time, after fixing its process group and session ID and so on; the child then exits too. The grandchild process is now autonomous and won't show up in the ps output for the the terminal where it was launched.

您可以查看 Unix环境中的高级编程,第三版W Richard Stevens和Stephen A Rago的Edn ,或在高级Unix编程,第二版Edn ,作者Marc J Rochkind,讨论了守护程序。

You can look at Advanced Programming in the Unix Environment, 3rd Edn by W Richard Stevens and Stephen A Rago, or at Advanced Unix Programming, 2nd Edn by Marc J Rochkind for discussions of daemonization.

我有一个程序 daemonize 将守护一个不知道如何守护自己的程序(正确)。编写该程序是为了解决程序中的缺陷,该程序本来可以使其自身守护进程,但无法正常工作。如果需要,请与我联系-查看我的个人资料。

I have a program daemonize which will daemonize a program that doesn't know how to daemonize itself (properly). It was written to work around the defects in a program which was supposed to daemonize itself but didn't do the job properly. Contact me if you want it - see my profile.

这篇关于nohup和守护程序之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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