Linux后台运行程序(&和nohup)

&

后台运行程序

使用ctrl+c发送SIGINT信号,程序不关闭
关闭session/终端时发送SIGHUP信号,程序关闭

示例:

storm nimbus &

程序运行的信息会输出到终端


nohup

不挂断(no hang up)运行程序

使用ctrl+c发送SIGINT信号,程序关闭
关闭session/终端时发送SIGHUP信号,程序不关闭

示例:

nohup storm nimbus

程序运行的信息会默认输出到nohup.out

也可以指定输出文件

nohup storm nimbus > output.log 2>&1

其中,2>&1的作用是,将标准错误2重定向到标准输出&1,再被重定向输入到output.log文件中。

0 – stdin (standard input,标准输入)
1 – stdout (standard output,标准输出)
2 – stderr (standard error,标准错误输出)

* 二者同时使用,可以使后台程序不受ctrl+c和session/终端关闭的影响。

原文地址:https://www.cnblogs.com/live41/p/15554700.html