Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a Cygwin PID to a Windows PID

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?

like image 607
Jazz Avatar asked Nov 05 '09 09:11

Jazz


3 Answers

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.

like image 132
Michael Dillon Avatar answered Nov 18 '22 07:11

Michael Dillon


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);
like image 22
Warren Young Avatar answered Nov 18 '22 08:11

Warren Young


The proc file system has the windows PID for cygwin PID $pid in /proc/$pid/winpid.

> notepad&
[1] 11716
> taskkill /f /pid $(</proc/$!/winpid)
ERFOLGREICH: Der Prozess mit PID 11976 wurde beendet.
[1]+  Exit 1                  notepad
like image 6
EndlosSchleife Avatar answered Nov 18 '22 06:11

EndlosSchleife