开发者

How to stop a process programmatically

I would like to ask how can I stop a process pro开发者_高级运维grammatically using C++?

Thanks.


This is a platform dependent question. Could you specify the platform you're worknig on?

For Windows you can use TerminateProcess

  • http://msdn.microsoft.com/en-us/library/ms686714(VS.85).aspx


It's platform-dependent. On Unix you'd send the process a signal with the kill(2).


Use exit function to terminate the calling process. If you want to terminate the process without executing destructors for objects of automatic or static storage duration you could use abort function.


#include <windows.h>
int main()
{
 system("taskkill /f /im process.exe"); 
// replace process.exe with the name of process you want to stop/kill
// /f is used to forcefully terminate the process
// /im is used for imagename or in simple word it's like wildcard
 return 0;
}

Or you can go to How to kill processes by name? (Win32 API)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜