简体   繁体   English

如何从ac程序终止exe

[英]How to terminate a exe from a c program

I am using a system() to call an executable program(A server) . 我正在使用system()调用可执行程序(服务器)。 Now after a certain time I want to terminate this program from my c program itself. 现在过了一段时间,我想从我的c程序本身终止该程序。 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) 作业系统正在执行:(http://rcn-ee.net/deb/rootfs/precise/ubuntu-12.04-r4-minimal-armhf-2012-07-16.tar.xz)

The best way to do this is to use a function that gives you more control over the resulting process than system() does. 做到这一点的最好方法是使用一个函数,该函数比system()可以更好地控制结果进程。 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. 对于Windows,请使用CreateProcess()返回一个HANDLE ,稍后您可以在TerminateProcess()使用该HANDLE TerminateProcess()进程。

  • 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. 对于Unix,请使用fork()exec() ,它们为您提供子进程的pid,您以后可以在kill()来终止该进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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