Nohup: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=


* nohup on wikipedia http://en.wikipedia.org/wiki/Nohup
* http://en.wikipedia.org/wiki/Nohup
* https://www.digitalocean.com/community/tutorials/how-to-use-bash-s-job-control-to-manage-foreground-and-background-processes


=Internal=
=Internal=
Line 11: Line 12:
<tt>nohup</tt> is a POSIX command to ignore the HUP (hangup) signal. The [[Linux_Signals#SIGHUP_.281.29|HUP signal]] is, by convention, the way a terminal warns dependent processes of logout.
<tt>nohup</tt> is a POSIX command to ignore the HUP (hangup) signal. The [[Linux_Signals#SIGHUP_.281.29|HUP signal]] is, by convention, the way a terminal warns dependent processes of logout.


<pre>
nohup command &
nohup command &
 
</pre>
nohup achieves this behavior by detaching from its [[Linux_General_Concepts#Session|session]] and [[Linux TTY#Overview|TTY]], so its child processes won't notice the HUP signal sent by the terminal on disconnection. stdout and stderr output that would normally go to the terminal goes to a file called ./nohup.out.
 
The name of the output files can be modified by redirecting the output streams ''inside'' the nohup command:
 
nohup command > my-stdout-file.out 2> my-stdout-file.out &


Output that would normally go to the terminal goes to a file called ./nohup.out if it has not already been redirected.
This command won't produce the default nohup.out file, but two my-stdout-file.out and my-stdout-file.out files.


Note that nohupping backgrounded jobs is typically used to avoid terminating them when logging off from a remote SSH session.  
Note that nohupping backgrounded jobs is typically used to avoid terminating them when logging off from a remote SSH session.  
Line 23: Line 28:
This problem can be overcome by redirecting all three I/O streams:
This problem can be overcome by redirecting all three I/O streams:


{{{
<pre>
$ nohup ./myprogram > foo.out 2> foo.err < /dev/null &
nohup ./myprogram > foo.out 2> foo.err < /dev/null &
}}}
</pre>


=Solution Used to Background gld Remotely=


!!!Solution Used to Background gld Remotely
<pre>
 
{{{
 
...
...


Line 42: Line 45:
...
...
fi
fi
 
</pre>
}}}
 
__Referenced by:__\\
[{INSERT com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE max=20, maxwidth=50}]

Latest revision as of 03:23, 3 May 2018

External

Internal

Overview

nohup is a POSIX command to ignore the HUP (hangup) signal. The HUP signal is, by convention, the way a terminal warns dependent processes of logout.

nohup command &

nohup achieves this behavior by detaching from its session and TTY, so its child processes won't notice the HUP signal sent by the terminal on disconnection. stdout and stderr output that would normally go to the terminal goes to a file called ./nohup.out.

The name of the output files can be modified by redirecting the output streams inside the nohup command:

nohup command > my-stdout-file.out 2> my-stdout-file.out &

This command won't produce the default nohup.out file, but two my-stdout-file.out and my-stdout-file.out files.

Note that nohupping backgrounded jobs is typically used to avoid terminating them when logging off from a remote SSH 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 be overcome by redirecting all three I/O streams:

nohup ./myprogram > foo.out 2> foo.err < /dev/null &

Solution Used to Background gld Remotely

...

if ${background}; then
    nohup ${command} 1>./gld.log 2>&1 < /dev/null &
    pid=$!
    echo "gld launched in background (pid ${pid}), use gld stop|status to interact with it"
    sleep 1
else
...
fi