nohup
In nohup is a POSIX command to the Unix signal " HUP to ignore" (hangup). This signal is used by a terminal to notify dependent processes about a logout . As a rule, dependent processes of the terminal would terminate as a result of the signal reception.
When using nohup
, the output of the process that should actually go to the terminal is nohup.out
written to a file named , if it has not already been redirected elsewhere .
nohup
is a primitive tool that configures a command in such a way that it ignores a certain signal. It is still a long way from offering a solution to all possible problems of asynchronous program operation, such as might be the case with a full batch processing system .
use
The following example starts the program foo
in the background so that it is not aborted by the subsequent logout:
$ nohup foo & $ exit
This prevents the process from receiving a STOP signal when it logs out . However, if an input / output takes place via the standard I / O ( stdin
, stdout
or stderr
), these will still cause the terminal to “hang” (see below).
nohup
is often used in conjunction with the nice command to influence the priority of the process.
$ nohup nice abcd &
Existing jobs and processes
Certain shells (e.g. bash ) have ready-made options for suppressing the sending or forwarding of the SIGHUP signal to existing jobs , even if these were not nohup
started. In bash this can be achieved by typing disown -h job
. If this command is called without arguments, the job is removed from the job table, which then also means that it does not receive the signal.
Before disown
an active job is applied, it should be Strg-Z
stopped with and then moved bg
to the background with the command. Another relevant bash option is shopt huponexit
, which can be used to ensure that a HUP signal is automatically sent to the jobs when the shell is closed in the normal way.
The AIX and Solaris versions of nohup
have an -p
option that causes a running process to ignore future SIGHUP signals. In contrast to disown
, as described above, nohup -p
process IDs accepted as parameters.
Avoiding terminal hanging
Applying nohup
to a background job is typically used to prevent it from terminating when an SSH session ends. Another problem arises if SSH does not allow this logout ("hangs") because no data should be lost from or for the background jobs. This problem can be solved by redirecting the I / O streams :
$ nohup ./programm > foo.out 2> foo.err < /dev/null &
It should also be noted that closing an SSH session does not always send an HUP signal to the dependent processes. Among other things, this depends on whether a pseudo-terminal was used.
Alternatives
- The
screen
or thetmux
command can also detach a process from the current shell. It is possible to bind the process again to the shell at a later point in time.
- For example, the following call will
script.sh
be executed in the background, ignoring SIGHUP :
$ screen -A -m -d -S somename ./script.sh &
- The
disown
command is used to remove jobs from the job table or to mark them not to receive the SIGHUP signal.
Web links
- nohup Solaris man pages
Individual evidence
- ^ Re: nohup / disown and logout . Zsh.org. February 7, 2005. Retrieved June 10, 2009.
- ↑ gnu.org
- ↑ gnu.org
- ↑ publib.boulder.ibm.com
- ^ SSH Frequently Asked Questions . Snailbook.com. Retrieved June 10, 2009.
- ↑ OpenSSH FAQ . Openssh.com. September 20, 2005. Archived from the original on July 10, 2009. Info: The archive link was automatically inserted and has not yet been checked. Please check the original and archive link according to the instructions and then remove this notice. Retrieved June 10, 2009.
- ↑ Bug 396 - sshd orphans processes when no pty allocated . Bugzilla.mindrot.org. Retrieved June 10, 2009.