"Nohup"
When the user SSH terminal disconnects or the network port, the terminal does not have the HUP signal to shut down all child processes.
Nohup causes the process to ignore the HUP signal and is not subject to terminal disconnection
Usually add "&" at the end to put the command in the interrupt background run
Nohup standard output and standard error output are redirected to the Nohup.out file
[[email protected] ~]# nohup ping www.ibm.com &[1] 3059nohup:appending output to ' nohup.out ' [[email protected] ~]# PS -ef |grep 3059root 3059 984 0 21:06 pts/3 00:00:00 ping www.ibm.comroot 3067 984 0 21:06 PTS/3 00:0 0:00 grep 3059[[email protected] ~]#
"&"
By including one or more commands in the (), you can have these commands run in a child shell
"&" is also placed in "()", found that the submitted job is not in the job list, that is, can not be viewed through jobs, so as to avoid the impact of the HUP signal, not affected by interrupted disconnection
[[Email protected] ~]# (ping www.ibm.com &) [[email protected] ~]# ps-ef |grep www.ibm.comroot 16270 1 0 14:1 3 pts/4 00:00:00 Ping www.ibm.comroot 16278 15362 0 14:13 pts/4 00:00:00 grep www.ibm.com[[email protected] ~]#
The parent Process ID (PPID) of the new process is 1 (the PID of the Init process), not the process ID of the current terminal, so it is not part of the current terminal's child process and is not affected by the hup signal of the current terminal.
"Screen"
Screen allows a large number of commands to run in a stable background
Screen provides a ansi/vt100 terminal emulator to run multiple fullscreen pseudo-terminals under a real-world terminal
SCREEN-DMS session name establish a conversation in disconnected mode and specify the session name
Screen-list Show All Sessions
Screen-r Session name reconnect to the specified conversation
Shortcut key Ctrl-a D temporarily disconnects the current session
Screen Example
[Email protected] ~]# SCREEN-DMS urumchi[[email protected] ~]# screen-listthere is a screen On:12842.urumchi (Detached) 1 Socket in/tmp/screens/s-root. [Email protected] ~]# screen-r Urumchi
When executing a command in screen, do not worry about the effect of the HUP signal because:
1. Process tree without using the screen's newly process
[[email protected] ~]# ping www.google.com &[1] 9499[[email protected] ~]# pstree-h 9499init─┬─xvnc├─acpid├ ─atd├─2*[sendmail]├─sshd─┬─sshd───bash───pstree│└─sshd───bash───ping
When we are not using screen, the bash we are in is the sshd subprocess, and when sshd disconnects, the HUP signal naturally affects all the sub-processes under the current sshd.
2. Process tree using the new process after screen
[[email protected] ~]# screen-r urumchi[[email protected] ~]# ping www.ibm.com &[1] 9488[[email protected] ~]# Pstree -H 9488init─┬─xvnc├─acpid├─atd├─screen───bash───ping├─2*[sendmail]
With screen, Bash is a child of screen, and screen is a subprocess of init (PID 1), and when you disconnect ssh, the HUP signal does not affect all of the child processes in screen.
Summarize:
nohup/& is undoubtedly the most convenient method for temporary needs, and screen is the perfect choice when it comes to high-volume operations that require stable environments.
Linux System program background running Nohup,&,screen, etc.