How Linux performs background processes

Source: Internet
Author: User

Linux executes a process directly. After the current instruction has ended. Or shut down the shell formation process will end.

How to perform processing in the background

Method 1

With the Nohup command, the nohup command itself means no hung up and he says that they will not receive a shell shutdown to close the process.

Use Nohup Command & to enable commands to execute in the background. You can see what's happening in the background through job-l.

The place where the pit is more than the assumption that the direct shutdown of the Shell,shell will also close the background of the command, exit the shell need to first through the command exit and then in the background to perform the ability to close

Method 2

Using scripts to execute in the background, for example I'm going to execute Mongod--dbpath= "abc" to start MongoDB.

Write a script test.sh first. The contents can be

#!/bin/sh

Mongod--dbpath= "abc" Start MongoDB &

#这里 & is very important. Otherwise, you cannot exit the current command.

Then execute the test.sh directly. This time MongoDB has started and executed the shutdown shell and will not stop. The question came, why would it be so, that someone on the web explained

Using test.sh execution will immediately end, MongoDB through the & sign in the background execution. The parent process that test.sh executes is the current shell. (Viewing the shell process number can be viewed via echo $$), test.sh execution ends, but Mongod does not end, test.sh is very responsible for hosting Mongod to the system init process. By Ps-ef|grep Mongod You can see that the parent process of Mongod is 1.

Method 3

Set Mongod's parent process directly to the INIT process via Setsid

Setsid mongod--dbpath= "abc" starts MongoDB, viewing the Mongod process discovers that its parent process is 1.

References: http://www.cnblogs.com/lwm-1988/archive/2011/08/20/2147299.html

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

How Linux performs background processes

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.