How to run the process in Linux

  

Linux runs a process directly, after the current command ends, or closes the shell window, the process will end.

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 will not be closed, closed. Drop the process.

Use nohup command & make the command run in the background, you can see the background running through job -l.

The place where the pit is compared is that if the shell is closed directly, the shell will also close the background command. To exit the shell, you need to run the command first and then close it to run in the background.

Method 2

Run in the background with a script, 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 &< Br>

#这& is important, otherwise you cannot exit the current command.

Then run test.sh directly. At this time mongodb has started and run the shutdown shell will not stop, the problem is coming, why is this, some people on the network explained that

running with test.sh will end immediately, mongodb is indicated by the & Run in the background, the parent process running test.sh is the current shell, (view the shell process number can be viewed by echo $$), test.sh runs over, but mongod will not run, test.sh will be very responsible Mongod is hosted to the system init process via ps -ef| Grep mongod can see that mongod's parent process is 1.

Method 3

Set mongod's parent process directly to init process via setsid

setsid mongod --dbpath="abc"Start mongodb, check the mongod process and find it The parent process is 1.

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

Copyright © Windows knowledge All Rights Reserved