nohup is a
POSIX
The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system- and user-level application programming interf ...
command which means "no hang up". Its purpose is to execute a command such that it ignores the
HUP (hangup) signal and therefore does not stop when the user logs out.
Output that would normally go to the terminal goes to a file called , if it has not already been redirected.
Use
The first of the commands below starts the program
abcd
in the background in such a way that the subsequent logout 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 standard I/O files (stdin, stdout, or stderr), they will still hang the terminal. See
Overcoming hanging, below.
nohup is often used in combination with the
nice
Nice ( , ; Niçard: , classical norm, or , nonstandard, ; it, Nizza ; lij, Nissa; grc, Νίκαια; la, Nicaea) is the prefecture of the Alpes-Maritimes department in France. The Nice agglomeration extends far beyond the administrative c ...
command to run processes on a lower priority.
$ nohup nice abcd &
Implementations
Some shells (e.g.
bash
Bash or BASH may refer to:
Arts and entertainment
* ''Bash!'' (Rockapella album), 1992
* ''Bash!'' (Dave Bailey album), 1961
* '' Bash: Latter-Day Plays'', a dramatic triptych
* ''BASH!'' (role-playing game), a 2005 superhero game
* "Bash" ('' ...
) provide a
shell builtin
In computing, a shell builtin is a command or a function, called from a shell, that is executed directly in the shell itself, instead of an external executable program which the shell would load and execute.
Shell builtins work significantly fast ...
that may be used to prevent
SIGHUP On POSIX-compliant platforms, SIGHUP ("signal hang up") is a signal sent to a process when its controlling terminal is closed. It was originally designed to notify the process of a serial line drop. SIGHUP is a symbolic constant defined in the head ...
being sent or propagated to existing jobs, even if they were not started with nohup. In bash, this can be obtained by using
disown
Disownment occurs when a parent renounces or no longer accepts a child as a family member, usually due to reprehensible actions leading to serious emotional consequences. Different from giving a child up for adoption, it is a social and interper ...
-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. Before using
disown
on an active job, it should be stopped by
Ctrl-Z
, and continued in the background by the
bg
command. Another relevant bash option is
shopt huponexit
, which automatically sends the HUP signal to jobs when the shell is exiting normally.
The
AIX
Aix or AIX may refer to:
Computing
* AIX, a line of IBM computer operating systems
*An Alternate Index, for a Virtual Storage Access Method Key Sequenced Data Set
*Athens Internet Exchange, a European Internet exchange point
Places Belgium
...
and
Solaris
Solaris may refer to:
Arts and entertainment Literature, television and film
* ''Solaris'' (novel), a 1961 science fiction novel by Stanisław Lem
** ''Solaris'' (1968 film), directed by Boris Nirenburg
** ''Solaris'' (1972 film), directed by ...
versions of nohup have a
-p
option that modifies a running process to ignore future SIGHUP signals. Unlike the above-described
disown
builtin of bash,
nohup -p
accepts process IDs.
The command has also been ported to the
IBM i
IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS in ...
operating system.
Overcoming hanging
Note that nohupping backgrounded jobs is typically used to avoid terminating them when logging off from a remote
SSH
The Secure Shell Protocol (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution.
SSH applications are based on a ...
session. A different issue that often arises in this situation is that ssh is refusing to log off ("hangs"), since it refuses to lose any data from/to the background job(s). This problem can also be overcome by
redirecting all three I/O streams:
$ nohup ./myprogram > foo.out 2> foo.err < /dev/null &
Also note that a closing SSH session does not always send a HUP signal to dependent processes, such as when a
pseudo-terminal has not been allocated.
Alternatives
* A
terminal multiplexer
A terminal multiplexer is a software application that can be used to multiplex several separate pseudoterminal-based login sessions inside a single terminal display, terminal emulator window, PC/workstation system console, or remote login session, ...
can run a command in a separate session, detached from the current terminal, which means that if the current session ends, the detached session and its associated processes keeps running. One can then reattach to the session later on.
:For example, the following invocation of
screen
Screen or Screens may refer to:
Arts
* Screen printing (also called ''silkscreening''), a method of printing
* Big screen, a nickname associated with the motion picture industry
* Split screen (filmmaking), a film composition paradigm in which mul ...
will run somescript.sh in the background of a detached session:
$ screen -A -m -d -S somename ./somescript.sh &
* The
disown
Disownment occurs when a parent renounces or no longer accepts a child as a family member, usually due to reprehensible actions leading to serious emotional consequences. Different from giving a child up for adoption, it is a social and interper ...
command is used to remove jobs from the job table, or to mark jobs so that a SIGHUP signal is not sent on session termination.
References
External links
nohup from Solaris's man pages
{{Core Utilities commands
Unix SUS2008 utilities
IBM i Qshell commands