我正在尝试使用在C++程序上打开多个并行进程。它们四个必须并行运行。但是当我的C++程序关闭时,我想杀死每个进程。这是我的尝试:
system("python okcsend.py & PID1=$! python okccnysend.py & PID2=$! python okc.py & PID3=$! python okccny.py & PID4=$!");当我试图杀死他们的时候,我是这样做的:
system("kill PID1; kill PID2; kill PID3; kill PID4");然而,我得到的是:
sh: 1: kill: Illegal number: PID1
sh: 1: kill: Illegal number: PID2
sh: 1: kill: Illegal number: PID3
sh: 1: kill: Illegal number: PID4这样做的正确方法是什么?
谢谢。
发布于 2015-04-27 08:12:07
您需要分别从每个进程中获取PID。
伪代码:
pid1 = system("python okcsend.py & echo $!)
pid2 = system("python okcsend.py & echo $!)
pid3 = system("python okcsend.py & echo $!)
pid4 = system("python okcsend.py & echo $!)然后你可以这样做:
system("kill " + pid1 + "; kill " + pid2 + "; kill " + pid3 + "; kill " + pid4 + ";");https://stackoverflow.com/questions/29885167
复制相似问题