nohup, &, 2> & 1 command analysis

nohup means uninterrupted operation, & mean running in the background, meaning 2> & 1 is the standard output and error output is redirected to the same file.
Simply put even turn off the console nohup runs, it still runs the operation.
https://blog.csdn.net/liuyanfeier/article/details/62422742 explain more thorough, I gave him a little supplement
can refer https://www.jianshu.com/p/747e0d5021a2

nohup command analysis

Assume a case, you want to run a background command how to do? The best way is to use &, plus at the end of a command &can be run in the background.

&Analysis examples

Suppose you have a program called 123.py python
code like this, something has to output.

import time
a = 1
while True:
        print("start to print sth")                                                                                                                       
        a+=1
        print("a=%s" %(a))
        time.sleep(2)

If you need to run it, then python3 123.py, can be redirected to the correct content log.txt. This time the command is
python3 123.py > log.txt

  • After the run, the console has always been like this, you can not carry out other operations.
su@DESKTOP-FA1P4IO:~$ python3 123.py >> log.txt
  • Plus a behind &after the operation can be something else.
suyuesheng@DESKTOP-FA1P4IO:~$ python3 123.py >> log.txt &
[2] 809
suyuesheng@DESKTOP-FA1P4IO:~$

But after closing the console, even if python3 123.py >> log.txt &there is behind &it will still be terminated process.
Because the receive signals hang off the terminal. nohup will not get hung up signal.

As the name nohup claims, ignore all sent to hang (SIGHUP) signals subcommand.
So that all SIGHUP signal to the command are ignored, the command will not receive SIGHUP signal.
What is the SIGHUP signal it?
Simple to understand may be the end of the terminal, the operating system will send SIGHUP signal to the daemon.

  • Use nohup look like this
su@DESKTOP-FA1P4IO:~$ nohup python3 123.py >> log.txt &
[3] 905

Guess you like

Origin www.cnblogs.com/sogeisetsu/p/11403326.html