> ## Content Index
> Fetch the complete content index at: https://til.codes/llms.txt
> Use this file to discover other available public pages before exploring further.

# How do I get a process to run in the background?
- URL: https://til.codes/how-do-i-get-a-process-to-run-in-the-background/
- Published: 2016-02-09T09:30:38.000Z
- Updated: 2016-02-09T09:30:38.000Z
- Author: Manu Ajith
- Tags: shell, daemon, process, background, server, #Import 2024-07-13 21:01

###### Simple / Usable things first

If you want a start script without much effort, you could use the upstart service. See the corresponding manual page and `/etc/init/*.conf` for examples. After creating such a process you can start your server by calling

```
service my server start

```

If you want more features, like specific limitations or permission management, you could try `xinetd`.

###### Using the shell

You could start your process like this:

```
nohup ./myexecutable &

```

The `&` tells the shell to start the command in the background, keeping it in the job list. On some shells, the job is killed if the parent shell exits using the `HANGUP` signal. To prevent this, you can launch your command using the nohup command, which discards the HANGUP signal.

However, this does not work, if the called process reconnects the HANGUP signal.

To be really sure, you need to remove the process from the shell's joblist. For two well known shells this can be achieved as follows:

```
bash:
./myexecutable &
disown <pid>

zsh:
./myexecutable &!

```

###### Killing your background job

Normally, the shell prints the PID of the process, which then can be killed using the kill command, to stop the server. If your shell does not print the PID, you can get it using

```
echo $!

```

directly after execution. This prints the PID of the forked process.

*Curated from [this](http://stackoverflow.com/questions/12486691/how-do-i-get-my-golang-web-server-to-run-in-the-background?ref=til.codes) answer in SO.*