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?
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.
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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With