nohup
From Wikipedia, the free encyclopedia
The introduction to this article provides insufficient context for those unfamiliar with the subject. Please help improve the article with a good introductory style. |
nohup is a Unix command that is used to run another command while suppressing the action of the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out. It is most often used to run commands in the background as daemons. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected. This command is very helpful when we have to run a huge list of batch jobs which are inter-dependent.
nohup is part of the GNU Coreutils.
Contents |
[edit] Example
The first of the commands below starts the program abcd
in the background in such a way that the subsequent log out does not stop it.
$ nohup abcd & $ exit
Note that these methods prevent the process from being sent a 'stop' signal on logout, but if input/output is being received for these files, they will still hang the terminal [1]. See Overcoming Hanging, below.
nohup is often used in combination with the nice command to run processes as a lower priority.
$ nohup nice abcd &
[edit] Existing jobs
Some shells (e.g. bash) provide a shell builtin that may be used to prevent SIGHUP being sent to existing jobs, even if they were not started with nohup. In bash, this can be obtained by using disown -h job
; using the same builtin without arguments removes the job from the job table, which also implies that the job will not receive the signal.
[edit] Overcoming hanging
Nohuping backgrounded jobs is for example useful when logged in via SSH, since backgrounded jobs can cause the shell to hang on logout due to a race condition [2]. This problem can also be overcome by redirecting all three I/O streams:
nohup myprogram > foo.out 2> foo.err < /dev/null &
[edit] Alternatives
There are other ways to accomplish the "keep program running while one logs out" ability. For example, you can run the program inside a GNU Screen-style screen multiplexer, and then detach the screen. The screen runs independently of the user's sessions, and can be reattached by any session of the user. This has the advantage of being able to continue to interact with the program once reattached (as opposed to nohup, which cannot reattach nohup'ed programs). A related alternative would be to run in a 'detachable' graphical session such as that provided by VNC.
Another would be to use 'setsid' which will run a program in a new session.
It is also possible to use "dislocate" for this.
Under GNU/Debian, it is possible to use /sbin/start-stop-daemon to daemonise a process
[edit] External links
|
![]() |
This Unix-related article is a stub. You can help by expanding it. |