polerto
polerto

Reputation: 1790

How to kill a nohup process?

I executed the following command

$ nohup ./tests.run.pl 0 &

now when I try to kill it (and the executions that are started from this script) using

$ kill -0 <process_id>

it does not work. How can I kill a nohupped process and the processes that runs via the nohupped script?

Thanks

Upvotes: 39

Views: 120553

Answers (5)

san shrestha
san shrestha

Reputation: 41

kill nohup process

ps aux |grep nohup

grep that PID kill -15 -1 16000 (will logout you) and clean on next login root

Upvotes: 4

user7321649
user7321649

Reputation: 171

I would do something like:

jobs

[1] + Running nohup ./tests.run.pl

kill %1

Upvotes: 17

Mike S.
Mike S.

Reputation: 4869

If you don't know the process ids and it might run various commands within a shell (or a loop), you can run jobs -l to list jobs and PIDs, then kill them.

See example:

ubuntu@app2:/usr/share/etlservice/bin$ jobs -l
[1]  27398 Running                 nohup ./extract_assessor_01.sh > job1.log &
[2]  27474 Running                 nohup ./extract_assessor_02.sh > job2.log &
[3]  27478 Running                 nohup ./extract_assessor_03.sh > job3.log &
[4]- 27481 Running                 nohup ./extract_assessor_04.sh > job4.log &
[5]+ 28664 Running                 nohup ./extract_assessor_01.sh > job1.log &
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 27398
sudo kill 27474[1]   Terminated              nohup ./extract_assessor_01.sh > job1.log
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 27474
[2]   Terminated              nohup ./extract_assessor_02.sh > job2.log
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 27478
[3]   Terminated              nohup ./extract_assessor_03.sh > job3.log
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 27481
[4]-  Terminated              nohup ./extract_assessor_04.sh > job4.log
ubuntu@app2:/usr/share/etlservice/bin$ sudo kill 28664
[5]+  Terminated              nohup ./extract_assessor_01.sh > job1.log
ubuntu@app2:/usr/share/etlservice/bin$

Upvotes: 6

trojanfoe
trojanfoe

Reputation: 122381

Simply kill <pid> which will send a SIGTERM, which nohup won't ignore.

You should not send a SIGKILL first as that gives the process no chance to recover; you should try the following, in order:

  • SIGTERM (15)
  • SIGINT (2)
  • SIGKILL (9)

Upvotes: 30

Mat
Mat

Reputation: 206659

kill -0 does not kill the process. It just checks if you could send a signal to it.

Simply kill pid, and if that doesn't work, try kill -9 pid.

Upvotes: 49

Related Questions