public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Cygwin kill utility //Was: cgwin_internal(): difference b/w CW_CYGWIN_PID_TO_WINPID and CW_GETPINFO_FULL for taking only dwProcessId ?
@ 2014-04-08  3:01 Lavrentiev, Anton (NIH/NLM/NCBI) [C]
  2014-04-08  3:18 ` Christopher Faylor
  0 siblings, 1 reply; 51+ messages in thread
From: Lavrentiev, Anton (NIH/NLM/NCBI) [C] @ 2014-04-08  3:01 UTC (permalink / raw)
  To: cygwin

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


^ permalink raw reply	[flat|nested] 51+ messages in thread

end of thread, other threads:[~2014-04-14  8:06 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-08  3:01 Cygwin kill utility //Was: cgwin_internal(): difference b/w CW_CYGWIN_PID_TO_WINPID and CW_GETPINFO_FULL for taking only dwProcessId ? Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2014-04-08  3:18 ` Christopher Faylor
2014-04-08  3:30   ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2014-04-08  9:01     ` Corinna Vinschen
2014-04-08 13:19       ` Buchbinder, Barry (NIH/NIAID) [E]
2014-04-08 13:34         ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2014-04-08 15:21           ` Christopher Faylor
2014-04-08 16:27             ` Tim Prince
2014-04-08 16:49               ` Christopher Faylor
2014-04-08 17:46                 ` Corinna Vinschen
2014-04-08 18:00                   ` Christopher Faylor
2014-04-08 17:59                 ` Lavrentiev, Anton (NIH/NLM/NCBI) [C]
2014-04-08 18:13                   ` We need steenking patches (Re: Cygwin kill utility...) Christopher Faylor
2014-04-09  2:21                     ` Steven Penny
2014-04-09  3:28                       ` Christopher Faylor
2014-04-09  5:04                         ` Steven Penny
2014-04-09  5:51                           ` Christopher Faylor
2014-04-09 14:55                             ` Steven Penny
2014-04-09 16:37                               ` Christopher Faylor
2014-04-09 16:49                                 ` Christopher Faylor
2014-04-09 16:50                               ` Warren Young
2014-04-09 17:02                                 ` Steven Penny
2014-04-09 17:13                                   ` Christopher Faylor
2014-04-09 17:43                                     ` Steven Penny
2014-04-09 19:14                                       ` Christopher Faylor
2014-04-10  2:05                                   ` Andrey Repin
2014-04-10  8:01                                     ` Corinna Vinschen
2014-04-11 11:05                                       ` Andrey Repin
2014-04-11 12:10                                         ` Corinna Vinschen
2014-04-12 22:50                                           ` Andrey Repin
2014-04-12 22:59                                             ` Christopher Faylor
2014-04-14  8:06                                             ` Corinna Vinschen
2014-04-10 13:05                                     ` Steven Penny
2014-04-10 15:12                                       ` Chris J. Breisch
2014-04-11  0:11                                         ` Steven Penny
2014-04-11  0:28                                           ` Chris J. Breisch
2014-04-11  0:39                                             ` Steven Penny
2014-04-11  2:40                                               ` Christopher Faylor
2014-04-11  2:46                                           ` Christopher Faylor
2014-04-09 17:05                                 ` Christopher Faylor
2014-04-10 23:15                                   ` Peter Rosin
2014-04-11  2:17                                     ` Christopher Faylor
2014-04-11  7:01                                       ` Peter Rosin
2014-04-11 12:10                                         ` Corinna Vinschen
2014-04-11 17:09                                           ` Christopher Faylor
2014-04-12 14:46                                             ` Corinna Vinschen
2014-04-12 16:56                                               ` Christopher Faylor
2014-04-09 17:09                               ` Robert Pendell
2014-04-08 15:44           ` Cygwin kill utility //Was: cgwin_internal(): difference b/w CW_CYGWIN_PID_TO_WINPID and CW_GETPINFO_FULL for taking only dwProcessId ? Adam Dinwoodie
2014-04-08 15:50             ` Corinna Vinschen
2014-04-08 16:24               ` Christopher Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).