c++ - Is it possible a kill a command launched using system api in C? If not any alternatives? -
i launching command using system api (i ok using api c/c++). command pass may hang @ times , hence kill after timeout.
using as:
system("command");
i want use this:
run command using system independent api (i don't want use createprocess since windows only) kill process if not exit after 'x' minutes.
i not know portable way in c nor c++ languages. ask alternatives, know possible in other languages. example in python, possible using subprocess
module.
import subprocess cmd = subprocess.popen("command", shell = true)
you can test if command has ended with
if cmd.poll() not none: # cmd has finished
and can kill :
cmd.terminate()
even if prefere use c language, should read documentation subprocess module because explains internally uses createprocess
on windows , os.execvp
on posix systems start command, , uses terminateprocess
on windows , sig_term
on posix stop it.
Comments
Post a Comment