Reputation: 163
I would like to ask how can I stop a process programmatically using C++?
Thanks.
Upvotes: 3
Views: 5033
Reputation: 1620
#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)
Upvotes: 0
Reputation: 99535
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.
Upvotes: 3
Reputation: 754525
This is a platform dependent question. Could you specify the platform you're worknig on?
For Windows you can use TerminateProcess
Upvotes: 4
Reputation: 84151
It's platform-dependent. On Unix you'd send the process a signal with the kill(2)
.
Upvotes: 3