Reputation: 5087
Here is my script (run.sh
):
rm -f nohup.out
nohup myproc &
tailf nohup.out
If I run the script (sh run.sh
) then press Control-C, myproc
will be terminated,
but if I comment the tailf nohup.out
part, myproc
will run on background as expected.
Am I doing anything wrong?
Upvotes: 2
Views: 698
Reputation: 3804
The problem is not SIGHUP
(which nohup
would catch) but SIGINT
which you send by pressing Control-C. This is propagated to your process.
See this blog post for more details.
From what I read from that post you could change your code to something like this:
setsid myproc 1> output.log 2>&1 &
tail -f output.log
If you dont want to use your own output redirection, you can still use nohup
:
setsid nohup ping -c 30 localhost &
tail -f nohup.out
Hope this helps!
Upvotes: 1