开发者

How can I kill a process in both Windows and Linux?

开发者 https://www.devze.com 2023-02-15 01:53 出处:网络
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);

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

0

精彩评论

暂无评论...
验证码 换一张
取 消