Site icon LinuxCommands.site

nohup command tutorial in linux/unix with examples and use cases

linux nohup command – run a command immune to hangups, with output to a non-tty

When the linux nohup command is used to run jobs (scripts) in the background, it can ignore the hangup signal and cooperate with output redirection to achieve long-term jobs (scripts) run in the background.

Plays a very important role in daily development.

Syntax

nohup COMMAND [ARG]...

Options

Examples & Use Cases

Run script in background

1.In terminal window 1, run the script in the background using the linux nohup command and then close this terminal window.

➜  nohup ./test.sh > /dev/null 2>&1 &
[1] 7799
➜  exit

2.Open a new terminal window 2 and use the linux ps command to query the script process.

➜  ~ ps -ef | grep "test.sh" | grep -v grep
ylspirit   7799      1  0 17:09 ?        00:00:00 /bin/bash ./test.sh
➜  ~

Exit mobile version