nohup 在运行 一个进程后台最后有& 符号时没有作用?

nohup has no effect when running a process background with ampersand in the end?

据我所知,nohup 可以保持进程 运行ning 而无需关心终端的退出。但是我发现,当我最后使用&符号(&)运行一个后台进程(没有nohup),然后从终端退出时,我仍然可以找到进程运行宁在机.

这是一个简单的例子;我 运行 下面的命令然后退出终端:

ping localhost &

但是,我发现 "ping" 进程仍在机器中 运行ning,即使我在这里没有使用 nohup。我是不是误解了 nohup 的实际用法?

您在从会话注销后看到您的进程仍然 运行ning 的原因可能是您的 shell 在注销时没有发送 sighup。 您可以通过 运行ning:

确认
shopt | grep hupon 

我假设它会 return 类似于 huponexit off...

不能保证每个 Linux/shell 都这样做,所以为了保持安全并让您的脚本可移植,我建议使用 nohup。例如

nohup ping localhost &

为了确认您也可以启用 huponexit,通过 运行ning

shopt -s huponexit

然后 运行 你的命令没有 nohup,logoff/exit shell 并检查你的进程是否仍然 运行ning.