Verify disown command

In Bash, the disown command issued by itself will remove backgrounded (via bg 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. The disown -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 via ps 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:

# we start a command in the background
$ cat /dev/urandom > test &
[1] 18533

# we see our command is still running
$ jobs
[1]+  Running                 cat /dev/urandom > test &

# we disown the backgrounded job
$ disown 1

# notice it is no longer in the job table
$ jobs

I usually only use disown if I run a potentially long-running command like a rsync or cp 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 or teeing it to a file, running it with nohup, or running it in screen (which allows you to retake ownership of the command/terminate afterwards).

Examples:

# capture stdout and stderr to separate logs
cat /dev/urandom >stdout.log 2>stderr.log

# capture stdout and stderr to the same log, and display to stdout as well
cat /dev/urandom 2>&1 | tee output.log

# run a command under nohup (doesn't require a disown or job control support)
nohup cat /dev/urandom </dev/null