I am using a system() to call an executable program(A server) . Now after a certain time I want to terminate this program from my c program itself. Does anyone know how to d
The best way to do this is to use a function that gives you more control over the resulting process than system()
does. However, this would be platform specific.
For Windows, use CreateProcess()
which returns a HANDLE
which you can use later in TerminateProcess()
to kill the process.
For Unix, use fork()
and exec()
which gives you the pid of the child process, which you can use later in kill()
to kill the process.