X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:content-type :content-transfer-encoding:mime-version; q=dns; s=default; b=ttg Xr7fYUvaHFfgLKvpavViw8Shw8ssS902dwrBr+SAwewlVCAHSLooSEXaZtLHJpNG qb+fdqFbujSfk9fX8StWcq8N/Hwm0+zWxyLpbofUsg3aBN6JHqeXKp2ycye0POmS VsIPwT/0PL8v5e82+xS66nYWt5eigMDT8G+cYxls= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:content-type :content-transfer-encoding:mime-version; s=default; bh=et7B6tfQG mAZYEa3kg14VBPkZ2k=; b=Y/kGwLqMVYIi7EvUGdw55qddMrBKAdDudNVZKEryn ASDzM1hlXMkrqv+IXxAo+XbZQSggV5rR5OkOEQXr1tBXW4YGfyf6lVWfFrU25c2+ dmQWFNZ72dqfGwzXVdTFRDtCMupUtXmyXdZ1imSEL9aPWUU9VTgHS3uJQhB8VuEl wI= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,MIME_BASE64_BLANKS,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: nihxway2out.hub.nih.gov X-IronPortListener: Outbound_SMTP X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhwFAIxlQ1OcKEe0/2dsb2JhbABZgwY7V4MKuWiGZlEZgQgWdIInAQQSERFXARUNAgYZBwIEHRMVAgEOAQQbGodXDZlRhHqKIqIuF4EpgTSLXIJmDzI1gRQEjwOFbYUghUaDZ4dfgXGBP4Ir From: "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" To: "cygwin AT cygwin DOT com" Subject: Cygwin kill utility //Was: cgwin_internal(): difference b/w CW_CYGWIN_PID_TO_WINPID and CW_GETPINFO_FULL for taking only dwProcessId ? Date: Tue, 8 Apr 2014 03:01:18 +0000 Message-ID: <5F8AAC04F9616747BC4CC0E803D5907D0C8AED9C@MLBXv04.nih.gov> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-IsSubscribed: yes Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id s3831cmk015338 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 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. http://msdn.microsoft.com/en-us/library/windows/desktop/ms684880%28v=vs.85%29.aspx HTH, Anton Lavrentiev Contractor NIH/NLM/NCBI