Vibz
Vibz

Reputation: 163

How to stop a process programmatically

I would like to ask how can I stop a process programmatically using C++?

Thanks.

Upvotes: 3

Views: 5033

Answers (4)

udit043
udit043

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

Kirill V. Lyadvinsky
Kirill V. Lyadvinsky

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

JaredPar
JaredPar

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

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84151

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

Upvotes: 3

Related Questions