Previous Table of Contents Next

Module 96


The external nohup command executes a UNIX command immune to the hang-up and quit signals; thus its name no hang-up. The primary objective of the nohup command is to have a process continue executing if you get logged off the system because of a terminal line hang-up.

C shell
The nohup command in C shell is a built-in command. This internal command does not redirect output to the nohup.out file like its System V counterpart.
Any command ending with an &, which places the process in background mode, is automatically immune to hang-up signals.


Following is the general format of the nohup command.

       nohup command [ options arguments ]


The following arguments may be passed to the nohup command.

command The command you wish to execute which will not terminate if a hang-up or quit signal is received.
options The options for the command
arguments The arguments for the command


The nohup command allows you to start a job and then log off the system. The job continues running even though a hang-up signal was sent to it. The standard output and standard error of nohup and your command are redirected to the file nohup.out. If nohup cannot create nohup.out, then it tries to write to $HOME/nohup.out. You can redirect the output by specifying the output file. For example,

       cj> nohup acmd 2>&1 > acmd.out &

executes the acmd in background, ignoring hang-up and quit signals. The output is sent to the acmd.out file.

If you want the nohup command to apply to several commands, you must write a shell script containing the desired commands. For example,

       cj> cat sortdata
       for FILE in data1 data2 data3 data4
         sort $FILE -o $FILE

The sortdata shell script sorts each file named data1 through data4. To run this script in background without terminating when you log off the system, you type

       cj> nohup sortdata &

You must be careful in applying the nohup command to commands on the shell command line. For example,

       cj> nohup command1; command2

nohups the first command but not the second.

If the following command is specified on the command line, the shell will complain about the syntax. You cannot specify subshell process as another command's arguments.

       cj> nohup ( command1 )


You usually use the nohup command to start long jobs and then log off the system. It can be used for jobs you want to execute and make certain they are not terminated if you are logged off the system or if a quit signal is received.


In this activity you use the nohup command to start a job in background, log off the system, log back in, and check on the process. Begin at the shell prompt.

1.  Type nohup spell /etc/passwd /etc/passwd /etc/passwd | wc > spchck & and press Return.
2.  Immediately press Ctrl-D to log off the system.
3.  Now log in to the system. Type your login name mylogin and press Return.
4.  When the system prompts you, type your password and press Return.
5.  As soon as you are logged back in type ps -u mylogin and press Return. Depending on the length of your passwd file and the speed of your system the spell command may still be executing. If it is not executing, check the output. If it is, wait for it to complete. You will have to check using ps periodically.
6.  Type cat spchck and press Return. There should be a line with the number of misspelled words that were found in the /etc/passwd file.
7.  Type rm spchck and press Return.
8.  Turn to Module 109 to continue the learning sequence.

Previous Table of Contents Next