Linux runs a process directly, and the process ends after the current command finishes, or when the shell window is closed.
How to run a process in the background
Method 1
Using the Nohup command, the nohup command itself means no hung up means that the shell is not closed and the process is closed.
Use Nohup Command & to enable commands to run in the background, and job-l to see what is running in the background.
The place where the pit is compared is if you close the Shell,shell, it will also close the background command, exit the shell must first through the command exit and then close in order to run in the background
Method 2
Use scripts to run in the background, for example I want to run Mongod--dbpath= "abc" to start MongoDB.
First, write a script test.sh, the content can be
#!/bin/sh
Mongod--dbpath= "abc" Start MongoDB &
#这里 & is important, you cannot exit the current command.
Then run the test.sh directly. This time MongoDB has been started and run off the shell will not stop, the problem comes, why so, someone on the network explained as
Use test.sh run will immediately end, MongoDB through the & to run in the background, test.sh run the parent process is the current shell, (view the shell process number can be viewed through the echo $$), Test.sh run the end, but Mongod will not run the end, TEST.SH will be responsible for hosting the Mongod to the system init process, through Ps-ef|grep Mongod can see the mongod of the parent process 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.
Reference: http://www.cnblogs.com/lwm-1988/archive/2011/08/20/2147299.html
How Linux runs the process in the background