markdown 如何在不获取nohup.out的情况下使用nohup命令?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 如何在不获取nohup.out的情况下使用nohup命令?相关的知识,希望对你有一定的参考价值。


nohup only writes to nohup.out if the output is otherwise to the terminal. If you redirect the output of the command somewhere else - including /dev/null - that's where it goes instead.
```
# doesn't create nohup.out
nohup command >/dev/null 2>&1
```

If you're using nohup, that probably means you want to run the command in the background by putting another & on the end of the whole thing:
```
# runs in background, still doesn't create nohup.out
nohup command >/dev/null 2>&1 &
```

On Linux, running a job with nohup automatically closes its input as well. On other systems, notably BSD and OS X, that is not the case, so when running in the background, you might want to close its input manually. While closing input has no effect on the creation or not of nohup.out, it avoids another problem: if a background process tries to read anything from standard input, it will pause, waiting for you to bring it back to the foreground and type something. So the extra-safe version looks like this:
```
# completely detached from terminal 
nohup command </dev/null >/dev/null 2>&1 &
```
Note, however, that this does not prevent the command from accessing the terminal directly, nor does it remove it from your shell's process group. If you want to do the latter, you can do so by running disown with no argument as the next command, at which point the process is no longer associated with a shell "job" and will not have any signals (not just HUP) forwarded to it from the shell.

以上是关于markdown 如何在不获取nohup.out的情况下使用nohup命令?的主要内容,如果未能解决你的问题,请参考以下文章

sh 如何在不获取nohup.out的情况下使用nohup命令?

一次线上nohup.out日志丢失的问题

Linux下如何不停止服务,清空nohup.out文件

nohup 日志切割

我可以更改“nohup.out”的名称吗?

关于Linux中nohup.out日志过大问题