nohup
进程与系统
用法
nohup <command> [args] &让命令忽略挂断信号,这样退出登录后它还在跑;它并不会帮你放到后台,`&` 得自己加,输出会悄悄堆在 ./nohup.out 里。
常用选项
| 选项 | 含义 |
|---|---|
| & | You add this yourself: nohup alone does not put the command in the background. |
| > out.log 2>&1 | Send output somewhere other than the default ./nohup.out. |
| < /dev/null | Detach stdin as well, so the command cannot stall waiting for input. |
示例
nohup ./server.sh > server.log 2>&1 &Start the server so it survives logout, with its own log file.
nohup make -j4 &Run a long build that keeps going after you disconnect; output lands in nohup.out.
看什么在跑、什么在吃机器。先弄清是什么,再决定杀不杀。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. nohup 是做什么的?
让命令忽略挂断信号,这样退出登录后它还在跑;它并不会帮你放到后台,`&` 得自己加,输出会悄悄堆在 ./nohup.out 里。
Q. 怎么写?
nohup <command> [args] & —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 3 个,完整列表在 man nohup。这条命令属于进程与系统。
相关命令
man 手册: man nohup