user1179510
user1179510

Reputation: 1023

How to terminate a exe from a c program

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 do this? OS running:(http://rcn-ee.net/deb/rootfs/precise/ubuntu-12.04-r4-minimal-armhf-2012-07-16.tar.xz)

Upvotes: 1

Views: 1157

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 993961

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.

Upvotes: 5

Related Questions