3

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

Thanks.

roalz
  • 2,699
  • 3
  • 25
  • 42
Vibz
  • 163
  • 2
  • 8

4 Answers4

4

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

For Windows you can use TerminateProcess

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
3

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

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
3

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.

Kirill V. Lyadvinsky
  • 97,037
  • 24
  • 136
  • 212
0
#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)

Community
  • 1
  • 1
udit043
  • 1,610
  • 3
  • 22
  • 40