Linux process is permanently running in the background

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.