views:

289

answers:

2

I have a process I spawn with a Cygwin shell script, and I am unable to kill it with the kill command. Even with the Cygwin kill with the -f option, I get this message:

kill: couldn't open pid 1234

I would like to try to kill it with PsKill, but I cannot find a way to convert the Cygwin PID to a Windows PID that PsKill will understand. How can I do that?

+1  A: 

Have you tried running the cygwin kill instead of the bash builtin? If it is a Windows PID then type:

/bin/kill -f 1234

or if it is a Cygwin PID then type:

/bin/kill -9 1234

As far as I know there is no API to Cygwin that you could call to translate a Cygwin PID to a Windows PID. However, you could parse the output of ps -W to do the conversion. Or, if you really, really don't want to do that, then have a look at the source code for the Cygwin ps command, and see where they get the pids from. The Cygwin ps source code is here.. You could write a small utility in C to take the Cygwin pid and give you a Windows pid.

Michael Dillon
Yes, it is the Cygwin kill I'm using. I tried /bin/kill -f -9 1234 and /bin/kill -9 1234 with no success. 1234 is a Cygwin PID.
Jazz
If you use -f, then you should give it the Windows PID from ps -W
Michael Dillon
+1  A: 

ps -W will show the Windows PID in addition to the Cygwin PID.

Or, you can do it programmatically like this:

#include <sys/cygwin.h>
winpid = cygwin_internal(CW_CYGWIN_PID_TO_WINPID, cygpid);
Warren Young
Yes, I know, but I was hoping for a direct way to do this instead of parsing the ps output.
Jazz
Added programmatic alternative
Warren Young