How can I kill a process in both Windows and Linux?
Is there easy way to kill a process using it开发者_Go百科s process ID (pid_t
in Linux and PROCESS_INFORMATION::dwProcessId
in Windows)?
linux: kill(pid, SIGKILL);
Windows: TerminateProcess(Handle, 1)
where you get Handle from OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
Note that both of these will simply kill the process, the target is given no chance to shut down properly. If you want to let the target get a chance to do this, use SIGHUP and then SIGTERM on linux. For windows, you could send WM_SYSCOMMAND/SC_CLOSE if you have the target applications main window handle, this can be found with EnumWindows and GetWindowThreadProcessId
精彩评论