Linux nohup Commands

Source: Internet
Author: User
Tags session id

We often need to start a long-running program in development, we need to close the SSH connection, and still keep the program running, for this we need to use the Nohup command. Of course, you can also use the screen command, I have introduced in the previous article, you can refer to.

Nohup command is not difficult to use, I did not know in depth before. The Nohup command was used during the recent development process because of the need to start the proxy service. But found that the proxy service after a period of time to close the SSH connection will be suspended, so a simple understanding of the nohup, in this record. In the process of solving this problem, I also try to use the screen command, but it is not resolved, the problem is rather strange, see the phenomenon should be related to the Proxy service itself and the server configuration.

The Nohup command is used to execute other commands while ignoring the sighup signal. When we close the SSH connection, the operating system sends a SIGHUP signal to the running program, which usually causes the process to exit, but the NOHUP command ignores the signal.

Let's look at some of the concepts in Linux:

    1. Process group: A collection of one or more processes, each of which has a unique process group ID, which is the ID of the process leader process.

    2. Session period: A collection of one or more process groups, with a unique session-period-first process (session leader). The ID of the session ID that is the lead process.

    3. The session period can have a separate control terminal (controlling terminal). The session first process connected to the control terminal is called the control process (controlling processes). The process that is currently interacting with the terminal is called the foreground process group, and the remaining process groups are called background process groups.

According to POSIX.1 definition:

    1. Hang-up signal (SIGHUP) The default action is to terminate the program.

    2. When the terminal interface detects a disconnected network connection, the hang-up signal is sent to the control process (session-first process).

    3. If the session first process terminates, the signal is sent to the foreground process group for that session period.

    4. A process exit causes an orphan process group to be generated if any of the orphaned process group processes are in the stop state, sending Sighup and sigcont signals to all processes in the process group.

Therefore, when the network is disconnected or the terminal window is closed, that is, after the SSH connection disconnects, the control process receives a SIGHUP signal exit, which causes the other process to exit during the session.

Using the background to run the command "&" does not get rid of the SSH process Group control, just put the process into the background process group. When the SSH connection is closed, the program is also exited.

Before we introduced the screen command, here we compare the nohup command with the screen command:

    1. The Nohup command only guarantees that a single specified process does not exit, and the screen command retains all processes during the entire session;

    2. The Nohup command is relatively simple and requires a screen command for complex human-computer interaction.

    3. The program executed by the Nohup command can only be killed by the kill command, and the screen command may be more friendly;

    4. The screen command preserves the environment settings of the session, and enables fast switching of the working environment by resuming the session;

    5. Relatively nohup occupies less resources, there is no need for interaction when the nohup can meet the needs;

Screen is a completely alternative to nohup. From a personal preference, also prefer screen, convenient and powerful:)

Linux nohup Commands

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.