简体   繁体   中英

Kill a process created with _spawnvp()

The Windows version of a program starts a process with

char * argv[..];
intptr_t childHandle = _spawnvp( _P_NOWAIT, "executable.exe", argv );

which works. The documentation says: "The return value from an asynchronous _spawnvp (_P_NOWAIT specified for mode) is the process handle." and thus I assume there should be also a kill command that takes this handle. How can I kill a process when I have an intptr_t?

_spawnvp returns a process handle, if you use it with the _P_NOWAIT argument. Using the Win32 API you can terminate the process:

UINT exitCode = 0;
intptr_t handle = _spawnvp(_P_NOWAIT, "executable.exe", argv );
if(TerminateProcess((HANDLE) handle, exitCode))
{
    // successful termination
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM