nohup和引号ampersand的区别

我们知道,&用来执行后台程序:

myprocess.out &

但往往我们会使用nohup, 这样:

nohup myprocess.out &

这是因为,单纯使用&来运行程序的时候,程序是在当前shell的子shell中后台运行的,当前shell如果退出,会给所有的子shell发送HUP信号。子shell收到HUP信号,就会退出了,当然,你后台运行的程序也就退出了。

想象一下,你登陆了一个远程终端,&启动了一个后台程序 ,然后你退出远程终端,结果。。你的后台程序也退出了,是不是有那么一点崩溃呢?

因此nohup就登场了,看这名字,nohup=NO+HUP,也就是拒绝HUP信号呗。当前进shell退出的时候,nohup会阻止HUP信号的传递给你的后台程序,防止上面悲剧的发生

nohup还有一个功能,可以把程序的STDOUT和STDERR默认输出重定向到nohup.out。在追踪程序日志的时候比较有用。而&没这功能,日志直接输出到屏幕上,如果shell关闭,意味着输出丢失

Ref

  • https://stackoverflow.com/questions/15595374/whats-the-difference-between-nohup-and-ampersand


《 “nohup和引号ampersand的区别” 》 有 5 条评论

  1. finasteride 1 mg without prescription Interface fluid syndrome in routine cataract surgery 10 years after laser in situ keratomileusis

  2. cost of cytotec tablets Figure 8 Effect of tamoxifen and raloxifene on the clearance of 3 H cholesteryl oleate labelled HDL in mice

  3. We only need food, shelter, and minimal health care to survive priligy tablet Nicholas cLHPVvdSVxvG 6 27 2022

  4. Korsakoff syndrome is characterized by memory problems and nerve damage buy priligy usa

回复 where to get generic cytotec pill 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

About Me

一位程序员,会弹吉他,喜欢读诗。
有一颗感恩的心,一位美丽的妻子,两个可爱的女儿
mail: geraldlee0825@gmail.com
github: https://github.com/lisuxiaoqi
medium: https://medium.com/@geraldlee0825