DEV Community

Benji πŸ™
Benji πŸ™

Posted on

TIL about the command `nohup`

TIL about the command nohup, which stands for "no hang up". It's a command that runs a process immune to hangup signals (SIGHUP).

When you close your terminal or log out then the shell normally sends a SIGHUP signal to all running processes which terminates them. nohup prevents this and allows processes to continue running even after you've close the terminal.

I particularly needed this because I was locally running an n8n workflow, and although there is a Docker container version, I didn't want the hassle in adding more containers that were already running and so if I could somehow find a way to run it as a daemon then that would be perfect. This was when I discovered nohup exists and is already installed by default on my macbook.

To use it (like a background Docker container), you use the command similar to below:

nohup command [arguments] > /dev/null 2>&1 &
Enter fullscreen mode Exit fullscreen mode

This means, run command [arguments] and any stdout/stderr just gets shoved into /dev/null (as my friend puts it, a rubbish bin where anything sent in is discarded ... like rafas opinions). The 2>&1 just means to redirect stderr to same place as stdout, and finally the last & is to run in the background

So in the end I ended up with the command:

nohup n8n start > /dev/null 2>&1 &
Enter fullscreen mode Exit fullscreen mode

Reference: https://www.digitalocean.com/community/tutorials/nohup-command-in-linux

Top comments (0)