1 /*-------------------------------------------------------------------------
6 * Copyright (c) 1996-2020, PostgreSQL Global Development Group
8 * This is a replacement version of kill for Win32 which sends
9 * signals that the backend can recognize.
14 *-------------------------------------------------------------------------
22 pgkill(int pid
, int sig
)
29 /* we allow signal 0 here, but it will be ignored in pg_queue_signal */
30 if (sig
>= PG_SIGNAL_COUNT
|| sig
< 0)
37 /* No support for process groups */
42 /* special case for SIGKILL: just ask the system to terminate the target */
47 if ((prochandle
= OpenProcess(PROCESS_TERMINATE
, FALSE
, (DWORD
) pid
)) == NULL
)
52 if (!TerminateProcess(prochandle
, 255))
54 _dosmaperr(GetLastError());
55 CloseHandle(prochandle
);
58 CloseHandle(prochandle
);
61 snprintf(pipename
, sizeof(pipename
), "\\\\.\\pipe\\pgsignal_%u", pid
);
63 if (CallNamedPipe(pipename
, &sigData
, 1, &sigRet
, 1, &bytes
, 1000))
65 if (bytes
!= 1 || sigRet
!= sig
)
73 switch (GetLastError())
75 case ERROR_BROKEN_PIPE
:
79 * These arise transiently as a process is exiting. Treat them
80 * like POSIX treats a zombie process, reporting success.
84 case ERROR_FILE_NOT_FOUND
:
85 /* pipe fully gone, so treat the process as gone */
88 case ERROR_ACCESS_DENIED
:
92 errno
= EINVAL
; /* unexpected */