[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 4


nohup Command

Purpose

Runs a command without hangups.

Syntax

nohup CommandArg ... ] [  ]

Description

The nohup command runs the command specified by the Command parameter and any related Arg parameters, ignoring all hangup (SIGHUP) signals. Use the nohup command 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.

Whether or not the nohup command output is redirected to a terminal, the output is appended to the nohup.out file in the current directory. If the nohup.out file is not writable in the current directory, the output is redirected to the $HOME/nohup.out file. If neither file can be created nor opened for appending, the command specified by the Command parameter is not invoked. If the standard error is a terminal, all output written by the named command to its standard error is redirected to the same file descriptor as the standard output.

Exit Status

This command returns the following exit values:

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
    

Related Information

The csh command, nice command, sh command.

The signal subroutine.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]