I issued the ^z; bg; disown
sequence in order to allow me to close an ssh session in which I am running a super-important long-running process. This process writes status output to stderr, and it has continued to do so even after being detached (verified with lsof, the stderr fd is open for r/w).
Is there a way to determine that the process has indeed been disowned (will not recv SIGHUP if the shell recvs one)?
In Bash, the
disown
command issued by itself will remove backgrounded (viabg
or&
) processes from the active job table, and mark them to not receive a SIGHUP on logout.You can also pass one or more jobs to disown, like
disown 1 3
. Thedisown -h
flag is useful if you want to keep jobs in the table, but still not SIGHUP on logout.You can view the job table by issuing the
jobs
command. After a successful background, it will show[1]+ command &
. After disowning a job, it should no longer display in the job table, and no longer be killed on logout. You can still view the process viaps ux
,top
, and other process-viewing utilities.After a job has been disowned, you can wait for it to terminate naturally or send a signal via
kill
to the PID to stop it.Because Bash is just removing the job from the list of running jobs to terminate and the file handles to your terminal's stdout and stderr are still open, you will continue to receive output from the job until your terminal device is closed (when you log out).
Examples:
I usually only use
disown
if I run a potentially long-running command like arsync
orcp
and afterwards decide I need to log out without terminating it. If you know you're going to run a command and log out, you can capture the output by piping ortee
ing it to a file, running it withnohup
, or running it inscreen
(which allows you to retake ownership of the command/terminate afterwards).Examples: