Fix Linux close SSH, terminal run program termination problem (including background)

Source: Internet
Author: User

Problem Description:

Each time ssh to the server, and then run a self-written service-side program, such as./myserver.sh, and then close the SSH or terminal, the discovery service can not be accessed.

A brief analysis of the following:

According to this blog post, SSH login will create a new session, a login shell-initiated session, usually by a session first process, a foreground process group, a background process group composed. Typically, the session first process is a login shell, such as bash. A process group is a collection of one or more processes that belong to a single session. In general, the parent process of another process in a process group is the ID of the process group leader process, and if the process group leader terminates, the other processes in the process group become orphaned, and the process group becomes the orphan process group. For background process groups, processes in the background process group can be written to terminal devices, but when a process in a background process group tries to read an end device , it receives a sigttin signal and then stops . When a process is made up of an orphan process group, Bash cannot know its PID, then it cannot be placed in the foreground, and when it tries to read the terminal, the read () call fails and the errno is set to Eio.

In summary, after SSH login, bash is its child process, once the session is terminated, all related processes of that session will be killed. Includes background processes. & is no use.

Solution:

So how do we solve this problem? Use the Nohup command. The Nohup command ignores the sigttin signal so that it can continue to run after the session ends.

For example above, you can use:

Nohup./myserver. SH &

The back of the & can add or not add, the difference is whether it is the background. It has nothing to do with hanging off.

The specific use of the method is mentioned in http://zjking.blog.51cto.com/976858/1117828 's blog post.

If you want to revert to the previous session before the end of the state, such as I use Nmap scan an IP segment, the next time you log in to see the scan results.

We can use the screen command.

1. Use screen to enter into the sub-interface, then Nmap-a xxxxxxx2. Press CTRL + A, D to pause the sub-interface. [detached] is displayed and returns to the parent interface.  3. What do you want to do?  4. View sub-interface status screen-ls447. pts-1.  Free (Detached) Here 447 is the process number of the sub-interface.  54476. The way to kill a sub-interface on a sub-interface is CTRL + H

Fix Linux close SSH, terminal run program termination problem (including 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.