A simple tutorial on Linux nohup command

  sonic0002        2020-08-08 01:14:50       1,942        1    

In our daily work, there might be need to run some important program for hours or even days without being abruptly terminated. In such case, we may want to run the program with command nohup.

nohup is the abbreviation of no hangup, i.e, don't hang up or terminate the process. This command will tell the process to ignore the system HUP signal. The HUP signal will be emitted when the terminal is exited or disconnected. Normally process will abort its execution when receiving this signal. 

Basic Syntax

The basic syntax for nohup is

nohup command arguments

or

nohup options

If you want to know more usage about this command, can run 

nohup --help

When want to check the command version, can run

nohup --version

Example

If want to run a program which will continue to run even if the shell exits, run below

nohup command

The output of the command will be stored in nohup.out, this file will normally reside in home directory or current directory.

If you want to redirect the output to a specified file, the redirection command can be used.

nohup ./myScript.sh > ~/output/myOutput.txt

In case a program needs to be launched at background, can append & to the command. If want to bring it back to front end, can run fg.

Now if want to run multiple programs at the same time with nohup, can do below.

nohup bash -c 'mkdir files && ping -c 1 baidu.com && ls'> output.txt

This will run mkdir, ping and ls commands and redirect output to output.txt.

Reference: https://mp.weixin.qq.com/s/uT1A-21QC2DsEir0ztmrpw

LINUX  NOHUP 

       

  RELATED


  1 COMMENT


Anonymous [Reply]@ 2022-04-27 15:36:38

tmux is the way to go. toons of options. never used nohup or needed, asfter screen and especialy tmux



  RANDOM FUN

The internet has a new 404 page