DEV Community

dejanualex
dejanualex

Posted on

Uninterrupted Processes in Linux: disown and nohup

The gist of it:

Using & causes the program to run in the background, so you'll get a new shell prompt instead of blocking the current shell until the program ends. E.g. sending sleep 1000 in the background:
Image description

Keep the process running:

When the controlling terminal is closed the HUP signal is sent to the process.

Image description

Now if you would like to keep the process running even if you log out of the system or close the terminal, nohup and disown might be handy. nohup and disown are largely unrelated; they suppress SIGHUP (hangup) signals so the program isn't automatically killed when the controlling terminal is closed.

nohup - run a command immune to hangups
disown- remove a job from the table of active jobs for the current shell. It is useful when you want to end a background process without killing it.

Conclusions

Summarizing all of the above, it will look something like this:

Image description

You can use this mechanism (nohup, disown) to run scripts or long-running processes, and if you want to check what is the output of your process you can tail -f ~/nohup.out

Top comments (0)