Skip to content

Commit

Permalink
check if process is already terminated
Browse files Browse the repository at this point in the history
git-svn-id: https://plibc.svn.sourceforge.net/svnroot/plibc/trunk/plibc@76 1596915d-9e13-0410-ab7f-96e59408e0f0
  • Loading branch information
ndurner committed Dec 20, 2010
1 parent 1aae761 commit 34201e3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/kill.c
Expand Up @@ -32,17 +32,30 @@ int _win_kill(pid_t pid, int sig)
if (sig == SIGKILL || sig == SIGTERM)
{
HANDLE h;
DWORD dw;
BOOL terminated;

h = OpenProcess(PROCESS_TERMINATE, FALSE, (DWORD) pid);
h = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, FALSE, (DWORD) pid);
if (!h)
{
SetErrnoFromWinError(GetLastError());
return -1;
}

if (!TerminateProcess(h, 0))
if (GetExitCodeProcess(h, &dw) && dw != STILL_ACTIVE)
{
SetErrnoFromWinError(GetLastError());
/* already killed */
CloseHandle(h);
return 0;
}

terminated = TerminateProcess(h, 0);
dw = GetLastError();
CloseHandle(h);

if (!terminated)
{
SetErrnoFromWinError(dw);
return -1;
}
else
Expand Down

0 comments on commit 34201e3

Please sign in to comment.