Jazz Jazz - 2 months ago 26
Bash Question

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?

Answer

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.

Comments