sheredom / subprocess.h

🐜 single header process launching solution for C and C++
The Unlicense
1.12k stars 97 forks source link

Add terminate #19

Closed pthom closed 4 years ago

pthom commented 4 years ago

This PR is a complement to the previous 'fix_exit' PR. It adds the possibility to terminate (kill) a process.

Doc is as follows:

Terminating a Process

To terminate a (possibly hung) previously created process you call subprocess_terminate like so:

int result = subprocess_terminate(&process);
if (0 != result) {
  // an error occurred!
}

Note that you still can call subprocess_destroy, and subprocess_join after calling subprocess_terminate; and that the return code filled by subprocess_join(&process, &process_return) is then guaranted to be non zero.

Point of attention: I had to add a forward dll declaration for TerminateProcess like so:

__declspec(dllimport) int __stdcall TerminateProcess(void *, unsigned int);

CI Builds: