如何杀死从系统功能调用后台进程 [英] How to kill background process from system function call
问题描述
我怎么能杀死使用C语言系统函数调用执行的后台进程。例如像我有一个编译的应用程序调用fooprocess。然后我想编写一个程序,将执行使用系统功能后台fooprocess应用程序,请您参阅下面的code,
How can I kill a background process that was executed using a system function call in C language. Like for example I have a compiled application call "fooprocess". Then I want to write a program that will execute the fooprocess application in the background using the system function, please kindly see below the code,
const char app[] = "fooprocess &";
system(app);
正如你可以看到有一个&安培;字符,这样我可以在后台运行的应用程序fooprocess。我怎么能杀死这个fooprocess?
As you can see there is a "&" character so that I can run the fooprocess application in the background. How can I kill this fooprocess?
非常感谢。
推荐答案
要与你需要它的PID进程进行交互。我不知道是否有可能与系统
但有另一种方法是用fork + exec来派生自己的过程。
To interact with the process you need its PID. I'm not sure if it's possible with system
but one alternative is to fork the process yourself using fork + exec.
这篇关于如何杀死从系统功能调用后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!