0

Linux 执行一段 shell 命令加与不加 nohup 到底有什么区别?

 2 years ago
source link: https://www.v2ex.com/t/802649
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Linux

Linux 执行一段 shell 命令加与不加 nohup 到底有什么区别?

  BaseException · 14 小时 54 分钟前 · 1682 次点击

请教 Linux 大佬、运维大佬,标题中的问题。下面我先抛砖引玉。

nohup 英文全称 no hang up (不挂起),用于在系统后台不挂断地运行命令,退出终端不会影响程序的运行。 nohup 命令,在默认情况下(非重定向时),会输出一个名叫 nohup.out 的文件到当前目录下,如果当前目录的 nohup.out 文件不可写,输出重定向到 $HOME/nohup.out 文件中。

以上来自 https://www.runoob.com/linux/linux-comm-nohup.html

执行一个 java 程序,使用命令 1 或 2

  1. java -jar xxx.jar >> ./xxx.log 2>&1 &
  2. nohup java -jar xxx.jar >> ./xxx.log 2>&1 &

我使用命令 1 执行的程序,在退出终端之后,进程依然很好的存活着啊,nohup 的真正作用是什么?

>> ./xxx.log 这个 >> 跟文件之间需要空格吗?还是有没有空格都一样,我经过测试似乎是一样达到目的的。我知道 > 是直接覆盖, >> 是追加到文件(如果之前文件存在且有内容)。

谢谢彦祖们。

第 1 条附言  ·  4 小时 48 分钟前

谢谢大家的热心回复


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK