30
votes

Hi i have the following process which i cant kill:

The process to be killed.

I am running cygwin in windows xp 32 bit.

I have tried issuing the following commands:

/bin/kill -f 4760
/bin/kill -9 5000
kill -9 5000
kill 5000

When i write /bin/kill -f 4760 i get the message, 'kill: couldn't open pid 4760'.

When i write /bin/kill -9 5000 i get the message, 'kill: 5000: No such process'.

I simply don't understand why this process cant be killed. Since it has a WINID shouldnt it be killed by /bin/kill -f 4760?

hope someone can help thx :)

7
1. start cygwin as Administrator user 2. Use the path /bin/kill (kill is a shell command in the bash shell) 3. /bin/kill -f <pid> should then work - Donal Tobin
1. start Cygwin terminal as Administrator user 2. Use the path /bin/kill (kill is special in the bash shell) 3. /bin/kill -9 -f <pid> should then work 4. It is possible for windows processes to be in a state where they can not be killed (such as being debugged) - Donal Tobin

7 Answers

24
votes

The process is locked from Windows most likely. The error you are getting "couldnt open PID XXX" points to this. To confirm try killing it with windows taskkill

    taskkill /PID 4760
12
votes

Strangely, the following works in Cygwin:

echo PID1 PID2 PID3 | xargs kill -f

For example:

ps -W | grep WindowsPooPoo | awk '{print $1}' | while read line; do echo $line | xargs kill -f; done;
2
votes

Different Windows programs will handle the signals that kill sends differently; they've never been designed to deal with them in the same way that Linux/Cygwin programs are.

The only reliable method for killing a Windows program is to use a Windows specific tool, such as Task Manager or Process Explorer.

That said, if you've not already, you may have luck with running your Cygwin terminal in administrator mode (right click on your shortcut and select "Run as administrator").

2
votes

The method presented by @Donal Tobin is correct:

kill -f <pid>

However, I don't need to log in as administrator.

2
votes

Create a file called killall.sh with this line

ps -W | grep $1 | awk '{print $1}' | while read line; do echo $line | xargs kill -f; done;

Then give it execute permissions.

chmod 777 killall.sh

In your .bash_profile add this line

alias killall="~/killall.sh"   (point it to the correct location)

Then you just have to type "killall [name]"

2
votes

killall.sh - Kill by process name.

#/bin/bash
ps -W | grep "$1" | awk '{print $1}' | xargs kill -f;

Usage:

$ killall <process name>
0
votes

For me this command does not work on Windows 10 in Cygwin:

$ kill -f 15916
bash: kill: (15916) - No such process

Instead of it, you can use next commands:

$ powershell kill -f 15916
$ netstat -ano | grep ':8080' | awk '{print $5}' | xargs powershell kill -f
$ netstat -ano | grep ':8080' | awk '{print $5}' | while read pid; do powershell kill -f $pid; done;
$ netstat -ano | grep ':8080' | awk '{sub(/\r/,"",$5) ; print $5}' | while read pid; do taskkill /F /PID $pid; done;
SUCCESS: The process with PID 15916 has been terminated.