How to terminate a exe from a c program

后端 未结 1 1986
挽巷
挽巷 2021-01-15 22:01

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

相关标签:
1条回答
  • 2021-01-15 22:40

    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.

    0 讨论(0)
提交回复
热议问题