How to kill a windows process in a cygwin terminal?

I have a problem regarding how to kill a process in Cygwin on Windows. I am completely new to Cygwin. But I have a task that I simply cant kill. I have tried issuing the following commands:

kill 4568
kill -9 4568
/bin/kill -f 4568

I have issued the commands in a separate Cygwin terminal since I cannot Ctrl+C it in the Cygwin terminal where the process run. I have searched all over the internet without success.


ps -W | awk '/calc.exe/,NF=1' | xargs kill -f

Or

ps -W | awk '$0~v,NF=1' v=calc.exe | xargs kill -f

Or

powershell kill -n calc

You may try:

taskkill /pid 4568

If you want a BASH only solution, try this: (it works for me)

    KILLPS="<My Process Name>"
    WINPS=`ps -W | grep -i $KILLPS`         # Make case-insensitive.
    PID=`echo $WINPS | cut -d' ' -f1` 
    /bin/kill -f "$PID"

NOTE: use /bin/kill, the embedded shell kill will not kill PIDs for general windows proccesses.


(From my answer to a similar question on SO):

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").


Two things to think about here:

  1. Get the correct PID, which is the WINPID.
  2. Use the right tool.

To get the correct WINPID to kill, use cat /proc/<PID>/winpid. I.e. run this:

ZID=$$; WINPID=$(cat /proc/${ZID}/winpid); echo "Kill WINPID: ${WINPID}"; ps; sleep 10 &

and immediately after do another ps.

The right tool to use is sysinternals PsKill64.exe -t <winpid> which also kills all descendants of the script process, which kill doesn't.