nohup

from Wikipedia, the free encyclopedia

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.outwritten to a file named , if it has not already been redirected elsewhere .

nohupis 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 fooin 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, stdoutor stderr), these will still cause the terminal to “hang” (see below).

nohupis 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 nohupstarted. 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 disownan active job is applied, it should be Strg-Zstopped with and then moved bgto 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 nohuphave an -poption that causes a running process to ignore future SIGHUP signals. In contrast to disown, as described above, nohup -pprocess IDs accepted as parameters.

Avoiding terminal hanging

Applying nohupto 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 screenor the tmuxcommand 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.shbe executed in the background, ignoring SIGHUP :
 $ screen -A -m -d -S somename ./script.sh &
  • The disowncommand is used to remove jobs from the job table or to mark them not to receive the SIGHUP signal.

Web links

Individual evidence

  1. ^ Re: nohup / disown and logout . Zsh.org. February 7, 2005. Retrieved June 10, 2009.
  2. gnu.org
  3. gnu.org
  4. publib.boulder.ibm.com
  5. ^ SSH Frequently Asked Questions . Snailbook.com. Retrieved June 10, 2009.
  6. 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. @1@ 2Template: Webachiv / IABot / www.openssh.com
  7. Bug 396 - sshd orphans processes when no pty allocated . Bugzilla.mindrot.org. Retrieved June 10, 2009.