This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Cygwin kill utility //Was: cgwin_internal(): difference b/w CW_CYGWIN_PID_TO_WINPID and CW_GETPINFO_FULL for taking only dwProcessId ?
- From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr at ncbi dot nlm dot nih dot gov>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Tue, 8 Apr 2014 03:01:18 +0000
- Subject: Cygwin kill utility //Was: cgwin_internal(): difference b/w CW_CYGWIN_PID_TO_WINPID and CW_GETPINFO_FULL for taking only dwProcessId ?
- Authentication-results: sourceware.org; auth=none
Hello,
It looks like in order to effectively kill the process by Windows means (i.e. what Cygwin "kill -f" is supposed to do),
the process handle must be obtained with the SYNCHRONIZE right (in addition to PROCESS_TERMINATE), otherwise
WaitForSingleObject() fails with code 5, permission denied (at least for a regular user, i.e. not an administrator).
That's about this portion of kill.cc located at winsup\utils:
HANDLE h = OpenProcess (PROCESS_TERMINATE, FALSE, (DWORD) dwpid);
if (!h)
{
if (!wait || GetLastError () != ERROR_INVALID_PARAMETER)
fprintf (stderr, "%s: couldn't open pid %u\n",
prog_name, (unsigned) dwpid);
return;
}
if (!wait || WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
if (sig && !TerminateProcess (h, sig << 8)
&& WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
fprintf (stderr, "%s: couldn't kill pid %u, %lu\n",
prog_name, (unsigned) dwpid, GetLastError ());
MSDN is in agreement with the observed behavior (access denied),
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684320%28v=vs.85%29.aspx
<quote>
The handle returned by the OpenProcess function can be used in any function that requires a handle to a process, such as the wait functions, provided the appropriate access rights were requested.
</quote>
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684880%28v=vs.85%29.aspx
HTH,
Anton Lavrentiev
Contractor NIH/NLM/NCBI