nohup and & run in the background, process viewing and termination

1.nohup

Purpose: Run a command without hanging up.

Syntax: nohup Command [ Arg … ] [ & ]

  Whether or not the output of the nohup command is redirected to the terminal, the output is appended to the nohup.out file in the current directory.

  If the nohup.out file in the current directory is not writable, the output is redirected to the $HOME/nohup.out file.

  The command specified by the Command parameter cannot be invoked if no file can be created or opened for appending.

Exit Status: The command returns the following exit values:   

  126 The command specified by the Command parameter can be found but not invoked.   

  127 The nohup command encountered an error or could not find the command specified by the Command parameter.   

  Otherwise, the exit status of the nohup command is the exit status of the command specified by the Command parameter.

2.&

Purpose: run in the background

Usually two are used together

nohup command &

eg:

1
nohup /usr/local/node/bin/node /www/im/chat.js >> /usr/local/node/output.log 2>&1 &

798214-20170320150831908-545166421.png

Process ID 7585

View running background processes

(1)jobs -l

798214-20170320150912955-1772662776.png

The jobs command only sees that the current terminal is in effect. After closing the terminal, the jobs running in the other terminal can no longer see the programs running in the background. At this time, use ps (process view command)

(2) ps -ef 

1
ps -aux|grep chat.js
 a: show all programs 
 u: Display in user-oriented format 
 x: Display all programs, not differentiated by terminal



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325266876&siteId=291194637