Ubuntu – How to kill the process using the name of the program instead of PID

processpython

I started my Python program in the background using nohup as mentioned below –

nohup zook.py &

Now I am trying to kill this process so I did the ps command as mentioned below

root@phxdbx1145:/home/david/zook# ps ax | grep zook.py
16352 pts/6    S+     0:00 grep --color=auto zook.py

But somehow, everytime its PID getting changed, I don't know why. Whenever I do like this –

kill -9 16352

It always say, No Such Process.

And when I do px command again, I see that PID got changed automatically..

So I am not sure how do I kill this process?

Is there any way I can kill the process with the name somehow?

UPDATE:-

This is what I am getting. I did pkill -9 zook.py and then I did ps command as mentioned below and it is shwoing zook.py constantly?

root@dbx1145:/home/david/zook# pkill -9 zook.py

root@dbx1145:/home/david/zook# ps ax | grep zook.py
23870 pts/6    S+     0:00 grep --color=auto zook.py

root@dbx1145:/home/david/zook# ps ax | grep zook.py
23872 pts/6    S+     0:00 grep --color=auto zook.py

root@dbx1145:/home/david/zook# ps ax | grep zook.py
23874 pts/6    S+     0:00 grep --color=auto zook.py

root@dbx1145:/home/david/zook# ps ax | grep zook.py
23876 pts/6    S+     0:00 grep --color=auto zook.py

Best Answer

Use killall:

killall <the_process_name>
Related Question