After we use SSH to connect the server, if it takes a very long time to execute a command, when the terminal is broken, the command will stop automatically after the SSH client executes the command, the default of his parent process is ssh, so when the SSH terminal is turned off, the child process is automatically killed. The workaround is to change the command process's parent process to init, so that the command will still run after SSH exits
By default:
[[email protected] ~]# Ping127.0.0.1&>/dev/NULL&[1]1782[[Email protected]~]# pstreeinit─┬─vboxservice───7*[{vboxservice}]├─abrtd├─acpid├─atd├─auditd───{auditd}├─console-kit-dae─── the*[{console-kit-da}] ├─crond├─dbus-Daemon├─dhclient├─hald───hald-runner─┬─hald-addon-Acpi│└─hald-addon-inpu├─master─┬─pickup│└─qmgr├─6*[Mingetty]├─redis-server───2*[{redis-Server}] ├─rsyslogd───3*[{rsyslogd}]├─sshd───sshd───bash─┬─ping-------->from the process tree, you can see that the parent process of the ping is SSH│└─PSTREE└─UDEVD───UDEVD
Workaround:
1. Using Nohup nohup Commond &[[Email protected]~]# nohup Ping127.0.0.1&>/dev/NULL&View process: [[email protected]~]# pstree init─┬─vboxservice───7*[{vboxservice}]├─abrtd├─acpid├─atd├─auditd───{auditd}├─console-kit-dae─── the*[{console-kit-da}] ├─crond├─dbus-Daemon├─dhclient├─hald───hald-runner─┬─hald-addon-Acpi│└─hald-addon-inpu├─master─┬─pickup│└─qmgr├─6*[Mingetty]├─ping---------->The Ping's parent process is already init ├─redis-server───2*[{redis-Server}] ├─rsyslogd───3*[{RSYSLOGD}]├─SSHD───SSHD───BASH───PSTREE└─UDEVD───UDEVD2. Using Setsid setsid Commond &[[Email protected]~]# Setsid Ping127.0.0.1&>/dev/NULL&view process; [[Email protected]~]# pstreeinit─┬─vboxservice───7*[{vboxservice}]├─abrtd├─acpid├─atd├─auditd───{auditd}├─console-kit-dae─── the*[{console-kit-da}] ├─crond├─dbus-Daemon├─dhclient├─hald───hald-runner─┬─hald-addon-Acpi│└─hald-addon-inpu├─master─┬─pickup│└─qmgr├─6*[Mingetty]├─ping---------->The Ping's parent process is already init ├─redis-server───2*[{redis-Server}] ├─rsyslogd───3*[{RSYSLOGD}]├─SSHD───SSHD───BASH───PSTREE└─UDEVD───UDEVD3. using (), (Commond &) [[email protected]~]# (Ping127.0.0.1&>/dev/NULL&) View the process tree: [[email protected]~]# pstreeinit─┬─vboxservice───7*[{vboxservice}]├─abrtd├─acpid├─atd├─auditd───{auditd}├─console-kit-dae─── the*[{console-kit-da}] ├─crond├─dbus-Daemon├─dhclient├─hald───hald-runner─┬─hald-addon-Acpi│└─hald-addon-inpu├─master─┬─pickup│└─qmgr├─6*[Mingetty]├─ping---------->The Ping's parent process is already init ├─redis-server───2*[{redis-Server}] ├─rsyslogd───3*[{RSYSLOGD}]├─SSHD───SSHD───BASH───PSTREE└─UDEVD───UDEVD
Linux process is permanently running in the background