Part of this is easy: To remove a job from your shell's process table, you can use disown
.
The part that's not easy is redirecting stdout and stderr away from the TTY. To do that, you can use gdb
to take control of the process and tell it to replace stdin, stdout and stderr (note that you'll need to be sure that this is also done on other subprocesses or threads that likewise need to survive the exit operation):
# for an instance of /path/to/program with PID 1234
# note that this is intended to be a transcript of content typed at a prompt -- it isn't a
# working shell script, since the commands after "gdb" are to be run *by gdb*, not the
# shell.
gdb /path/to/program
attach 1234
p dup2(open("/dev/null", 1), 0)
p dup2(open("stdout-file", 1), 1)
p dup2(open("stderr-file", 1), 2)
detach
quit
This has been automated as a tool called dupx
.
nohup
is generally pretty useless. Redirect stdin, stdout and stderr to a non-TTY source; tell the shell to set the HUP signal up to be discarded, use thedisown
builtin to remove a job from your shell's process table, and you've accomplished everythingnohup
would otherwise do without needing to use the command.nohup
?nohup
" has an utterly brain-deadnohup.out
redirection target default.