4

I have multiple scripts that detach a process from bash using nohup and &>/dev/null &. My question is, how do I kill the process after completely detaching it from bash. using killall or pidof ScriptName doesn't work.

6

nohup should only affect the hangup signal. So kill should still work normally. Maybe you are using the wrong pid or process name; compare with pstree -p or ps -ef.

If you still suspect nohup, maybe you could try disown instead.

$ sleep 1000 &
$ jobs -p
13561
$ disown
$ jobs -p
$ pidof sleep
13561
$ kill 13561
$ pidof sleep
$
1

If you used nohup, you can't kill them. The nohup command specifically prevents those processes from receiving the kill signals. If you simply used &, you can kill them by sending a kill or kill -9 to the PID. Well, you can kill them by rebooting the machine, but that might be a bit more extreme than you really want...

  • Closing the terminal still kills the process. Is there any way I can keep that from happening? – Kookerus Jul 7 '15 at 18:09
  • With nohup, closing the terminal should not kill the process, it should simply transfer the process's PPID to init. nohup is exactly what you should use to prevent that. Alternately, if you want to reconnect to it later, wrap it in a screen session. – John Jul 7 '15 at 18:11
  • 1
    nohup does not make the process immune to kill signals, it makes the process ignore a hup signal, you can kill it with kill <pid> and it will die like the rest of them. – 0x7c0 Jul 7 '15 at 18:13
  • I'm sorry, let me rephrase. When just using & and not nohup, closing the terminal kills the process. I want to disconnect the job from the terminal, but still be able to kill it if I want. Is there a way to do that? – Kookerus Jul 7 '15 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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