nohup

Synopsis

Description

The nohup utility invokes the named command with the arguments supplied. When
the command is invoked, nohup arranges for the SIGHUP signal to be
ignored by the process.

When invoked with the -p or -g flags, nohup arranges for processes
already running as identified by a list of process IDs or a
list of process group IDs to become immune to hangups.

The nohup utility can be used when it is known that command
takes a long time to run and the user wants to log
out of the terminal. When a shell exits, the system sends its
children SIGHUP signals, which by default cause them to be killed. All stopped,
running, and background jobs ignores SIGHUP and continue running, if their invocation
is preceded by the nohup command or if the process programmatically has
chosen to ignore SIGHUP.

The nohup utility can be used when it is known that a
particular command will take a long time to run and a user
wants to log out of the terminal. When a shell exits, the
system sends its children SIGHUP signals, which, by default cause them to
be killed. All stopped, running, and background jobs ignore SIGHUP and continue running,
if their invocation is preceded by the nohup command or if the
process programmatically has chosen to ignore SIGHUP.

The nohup utility causes processes to ignore SIGHUP but does not in
any way protect those processes from other signals. Since modern shells sometimes
send signals other than SIGHUP upon logout, it is possible for jobs
running under /usr/bin/nohup to be killed when the controlling shell exits.

/usr/bin/nohup

Processes run by /usr/bin/nohup are immune to SIGHUP (hangup) and SIGQUIT (quit) signals.

/usr/bin/nohup-p [-Fa]

Processes specified by ID are made immune to SIGHUP and SIGQUIT, and all output to the controlling terminal is redirected to nohup.out. If -F is specified, nohup forces control of each process. If -a is specified, nohup changes the signal disposition of SIGHUP and SIGQUIT even if the process has installed a handler for either signal.

/usr/bin/nohup-g [-Fa]

Every process in the same process group as the processes specified by ID are made immune to SIGHUP and SIGQUIT, and all output to the controlling terminal is redirected to nohup.out. If -F is specified, nohup forces control of each process. If -a is specified, nohup changes the signal disposition of SIGHUP and SIGQUIT even if the process has installed a handler for either signal.

/usr/xpg4/bin/nohup

Processes run by /usr/xpg4/bin/nohup are immune to SIGHUP.

The nohup utility does not arrange to make processes immune to a SIGTERM (terminate) signal, so unless they arrange to be immune to SIGTERM or the shell makes them immune to SIGTERM, they receive it.

If nohup.out is not writable in the current directory, output is redirected to $HOME/nohup.out. If a file is created, the file has read and write permission (600. See chmod(1). If the standard error is a terminal, it is redirected to the standard output, otherwise it is not redirected. The priority of the process run by nohup is not altered.

Options

The following options are supported:

-a

Always changes the signal disposition of target processes. This option is valid only when specified with -p or -g.

-F

Force. Grabs the target processes even if another process has control. This option is valid only when specified with -p or -g.

-g

Operates on a list of process groups. This option is not valid with -p.

-p

Operates on a list of processes. This option is not valid with -g.

Operands

The following operands are supported:

pid

A decimal process ID to be manipulated by nohup-p.

pgid

A decimal process group ID to be manipulated by nohup-g.

command

The name of a command that is to be invoked. If the command operand names any of the special shell_builtins(1) utilities, the results are undefined.

argument

Any string to be supplied as an argument when invoking the command operand.

Usage

Caution should be exercised when using the -F flag. Imposing two controlling
processes on one victim process can lead to chaos. Safety is assured
only if the primary controlling process, typically a debugger, has stopped the
victim process and the primary controlling process is doing nothing at the moment
of application of the proc tool in question.

Examples

Example 1 Applying nohup to Pipelines or Command Lists

It is frequently desirable to apply nohup to pipelines or lists of
commands. This can be done only by placing pipelines and command lists
in a single file, called a shell script. One can then issue:

example$ nohup sh file

and the nohup applies to everything in file. If the shell script
file is to be executed often, then the need to type sh
can be eliminated by giving file execute permission.

Add an ampersand and the contents of file are run in the
background with interrupts also ignored (see sh(1)):

See Also

Warnings

If you are running the Korn shell (ksh(1)) as your login shell,
and have nohup'ed jobs running when you attempt to log out, you
are warned with the message:

You have jobs running.

You need to log out a second time to actually log out.
However, your background jobs continues to run.

Notes

The C-shell (csh(1)) has a built-in command nohup that provides immunity from
SIGHUP, but does not redirect output to nohup.out. Commands executed with `&' are
automatically immune to HUP signals while in the background.

nohup does not recognize command sequences. In the case of the following
command,