Hi all,
Is there any chance of getting Process.kill support on Win32? I took a
look at the Perl source, here’s a basic implementation, with one
modification:
/* Doesn’t include any error checking /
/ A simple test worked on my Win2k box */
#include <windows.h>
int kill(int sig, DWORD pid)
{
HANDLE hThread;
DWORD dwThreadId;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,TRUE,pid);
if(hProcess)
{
switch(sig)
{
/* Check to see if process is running /
case 0:
return 0;
/ Handle a Ctrl-C
case 2:
if(GenerateConsoleCtrlEvent(CTRL_C_EVENT,pid))
{
return 0;
}
case 9:
if(TerminateProcess(hProcess,sig))
{
CloseHandle(hProcess);
return 0;
}
default:
hThread=CreateRemoteThread(hProcess,NULL,0,(LPTHREAD_START_ROUTINE)
(GetProcAddress(GetModuleHandle(“KERNEL32.DLL”),
“ExitProcess”)),
0,0,&dwThreadId);
if (hThread)
{
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
}
CloseHandle(hProcess);
}
}
return -1;
}
/* end code */
The modification is the “default:” case, where a few people on
comp.os.windows.programmer* suggest that calling TerminateProcess is a
bad idea, because it may not release resources properly and DLL’s may
not get detach notifications.
The drawback is that this won’t work on Windows 95 (not sure about 98).
Any chance of adding this to 1.8?
Regards,
Dan