6

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
2
  • Why are you using root?
    – user25656
    Dec 28, 2013 at 6:10
  • I have root access.. These are our machines for our project.
    – arsenal
    Dec 28, 2013 at 6:10

6 Answers 6

5

Use killall:

killall <the_process_name>
6
  • In this case, what it should be? killall zook.py
    – arsenal
    Dec 28, 2013 at 5:53
  • @TechGeeky: yes... that should kill the script... as for my experience with killing bash scripts, it works; sometimes I do have to kill other running processes started by the script...
    – rusty
    Dec 28, 2013 at 6:00
  • 1
    It doesn't work for me somehow.. It is saying no such process..
    – arsenal
    Dec 28, 2013 at 6:01
  • probably the script's already killed... did you try killing the invoked processes ?
    – rusty
    Dec 28, 2013 at 6:03
  • How do I do that? This is what I am getting when I did ps ax | grep zook.py 23248 pts/6 S+ 0:00 grep --color=auto zook.py
    – arsenal
    Dec 28, 2013 at 6:06
3

The pid in your example, the one that keeps changing, is the process ID of your grep trying to find the PID. That means that your ps and grep is not finding the actual process that you are looking for.

Try running your script without the trailing "&", to see what it is doing. Odds are it's failing quietly on you and not actually starting at all.

You can also use the System Monitor tool from the dash to see the full list of processes with process IDs.

3
  • I am in Ubunut which is not have nice UI.. Everything is command line.. How do I check all the processes ?
    – arsenal
    Dec 28, 2013 at 6:11
  • @TechGeeky, use top command for this.
    – rusty
    Dec 28, 2013 at 6:18
  • If you can install software, try 'htop'. It is nicer and easier to use (IMHO). Dec 30, 2013 at 8:12
2

you can use pkill to send kill signal same as kill signal

Eg: pkill firefox 
pkill -9 firefox
1
  • Bad example, in many ways! Oct 27, 2017 at 21:11
2

You can kill with xkill. Just go to the "run" dialog (Alt+F2), type in xkill and your mouse pointer will change to an "x". Point on the application that you want to kill and click, and it'll be killed. Can sometimes be much quicker than loading the System Monitor.

1

The basic problem is with the command 'ps ax | grep something'. This always lists 'grep ... something' as one of the process, which is in fact the 'grep' started by you. use 'pgrep ' instead to get the pid

see: https://unix.stackexchange.com/questions/74185/how-can-i-prevent-grep-from-showing-up-in-ps-results

0

Best answered here, https://askubuntu.com/a/760514/877732

If myName is not the process name or for example, is an argument to another (long) command, pkill (or pgrep) might not work as expected. So you need to use the -f option.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .