After we use SSH to connect to the server, if it takes a very long time to execute a command, the command stops automatically when the terminal is broken off.
In general, after the SSH client executes the command, the default of his parent process is ssh, so the SSH terminal is turned off, the child process is automatically killed, the solution is to change the command process of the parent process is init, then SSH exit, the command will still run
By default:
[[email protected] ~]# ping 127.0.0.1 &>/dev/null &
[1] 1782
[Email protected] ~]# Pstree
Init─┬─vboxservice───7*[{vboxservice}]
├─abrtd
├─acpid
├─atd
├─AUDITD───{AUDITD}
├─CONSOLE-KIT-DAE───63*[{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 ping 127.0.0.1 &>/dev/null &
To view a process:
[Email protected] ~]# Pstree
Init─┬─vboxservice───7*[{vboxservice}]
├─abrtd
├─acpid
├─atd
├─AUDITD───{AUDITD}
├─CONSOLE-KIT-DAE───63*[{CONSOLE-KIT-DA}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│└─hald-addon-inpu
├─master─┬─pickup
│└─qmgr
├─6*[mingetty]
├─ping---------->ping's parent process is already init.
├─redis-server───2*[{redis-server}]
├─RSYSLOGD───3*[{RSYSLOGD}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
2. Using Setsid setsid Commond &
[Email protected] ~]# setsid ping 127.0.0.1 &>/dev/null &
View process;
[Email protected] ~]# Pstree
Init─┬─vboxservice───7*[{vboxservice}]
├─abrtd
├─acpid
├─atd
├─AUDITD───{AUDITD}
├─CONSOLE-KIT-DAE───63*[{CONSOLE-KIT-DA}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│└─hald-addon-inpu
├─master─┬─pickup
│└─qmgr
├─6*[mingetty]
├─ping---------->ping's parent process is already init.
├─redis-server───2*[{redis-server}]
├─RSYSLOGD───3*[{RSYSLOGD}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
3. Use (), (Commond &)
[[Email protected] ~]# (ping 127.0.0.1 &>/dev/null &)
To view the process tree:
[Email protected] ~]# Pstree
Init─┬─vboxservice───7*[{vboxservice}]
├─abrtd
├─acpid
├─atd
├─AUDITD───{AUDITD}
├─CONSOLE-KIT-DAE───63*[{CONSOLE-KIT-DA}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│└─hald-addon-inpu
├─master─┬─pickup
│└─qmgr
├─6*[mingetty]
├─ping---------->ping's parent process is already init.
├─redis-server───2*[{redis-server}]
├─RSYSLOGD───3*[{RSYSLOGD}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
This article is from the "Study-everyday" blog, make sure to keep this source http://studys.blog.51cto.com/9736817/1677621
Linux processes are not affected by the terminal