nohup Command

Purpose

Runs a command without hangups.

Syntax

nohup { -p pid | CommandArg ... ] [ & ] }

Description

The nohup command runs the command specified by the Command parameter and any related Arg parameters, ignoring all hangup (SIGHUP) signals or modifies the process specified with -p option to ignore all hangup (SIGHUP) signals.

The nohup command can also be used to run programs in the background after logging off. To run a nohup command in the background, add an & (ampersand) to the end of the command.
Note: -p pid and Command can not be specified together.
When -p pid is used, the output of the specified process will not be re-directed to nohup.out.

Flags

Item Description
-p pid pid is the process-id of a running process. The nohup command modifies the specified process, to ignore all hangup (SIGHUP) signals.

Exit Status

This command returns the following exit values:

Item Description
126 The command specified by the Command parameter was found but could not be invoked.
127 An error occurred in the nohup command or the command specified by the Command parameter could not be found.

Otherwise, the exit status of the nohup command is that of the command specified by the Command parameter.

Examples

  1. To run a command in the background after you log off, enter:
    $ nohup find / -print &
    After you enter this command, the following is displayed:
    670
    $ Sending output to nohup.out
    The process ID number changes to that of the background process started by & (ampersand). The message Sending output to nohup.out informs you that the output from the find / -print command is in the nohup.out file. You can log off after you see these messages, even if the find command is still running.
  2. To run a command in the background and redirect the standard output to a different file, enter:
    $ nohup find / -print >filenames &
    This example runs the find / -print command and stores its output in a file named filenames. Now only the process ID and prompt are displayed:
    677
    $
    Wait before logging off because the nohup command takes a moment to start the command specified by the Command parameter. If you log off too quickly, the command specified by the Command parameter may not run at all. Once the command specified by the Command parameter starts, logging off does not affect it.
  3. To run more than one command, use a shell procedure. For example, if you write the shell procedure:
    neqn math1 | nroff > fmath1
    and name it the nnfmath1 file, you can run the nohup command for all of the commands in the nnfmath1 file with the command:
    nohup sh nnfmath1
  4. If you assign execute permission to the nnfmath1 file, you get the same results by issuing the command:
    nohup nnfmath1
  5. To run the nnfmath1 file in the background, enter:

    nohup nnfmath1  
    &

  6. To run the nnfmath1 file in the Korn shell, enter:
    nohup ksh nnfmath1
  7. To make a running process ignore all hangup signals, enter:
    nohup -p 161792