4

I have a situation where I'm not able to run nohup -p <processid> in Linux RHEL 6.6 box it says this option is not supported. I read the manpage and in Linux it had only --help and --version as options in Linux.

Is there any other alternative for nohup -p, to allow an already-running process to survive an exit of the running terminal?

3
  • 1
    ...also, frankly, 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 the disown builtin to remove a job from your shell's process table, and you've accomplished everything nohup would otherwise do without needing to use the command. Commented Jul 21, 2016 at 18:53
  • @CharlesDuffy so 3 steps, that can be done in one nohup? Commented Jul 21, 2016 at 18:58
  • 2
    Ahh, but your three steps force the user to think about what they're doing and make explicit decisions, whereas your "one nohup" has an utterly brain-dead nohup.out redirection target default. Commented Jul 21, 2016 at 18:59

1 Answer 1

4

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.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.