How to completely detach a process
It's a little hard to diagnose, as you don't give source for myproc
, but I suspect that your problem has something to do with "controlling TTY". I wrote a small shell script that just calls sleep 100
. I ran it under nohup
:
$ nohup ./sleeper > sleeper.out &
[1] 25305
-bash-3.2$ jobs
[1]+ Running nohup ./sleeper > sleeper.out &
-bash-3.2$ ps -l -p 25305
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 429624 25305 18252 0 77 0 - 15961 wait pts/0 00:00:00 sleeper
If you look at the ps
output, you see a column named "TTY". At least some versions of nohup
(the one I used above is from GNU coreutils, version 5.97, so relatively old). When I exited the bash shell from which I started sleeper
, the TTY column changed to '?', meaning that sleeper
didn't have one.
If myproc
doesn't deliberately detach itself from it's controlling TTY, it's still possible to get things like a SIGPIPE signal if it tries to write to stdout. It seems to me other things are possible, but I can't recall or google anything up.
If you can find or compile "daemonize", you might want to try it. If myproc
is compiled, you could modify the source to call the daemon(3)
library function.
You can use at
for this.
The
at
utility shall read commands from standard input and group them together as an at-job, to be executed at a later time.The at-job shall be executed in a separate invocation of the shell, running in a separate process group with no controlling terminal, except that the environment variables, current working directory, file creation mask, and other implementation-defined execution-time attributes in effect when the at utility is executed shall be retained and used when the at-job is executed.
echo myproc | at now
...will work, though on some systems you need to configure that at
daemon monitor first.