sh 杀死非法数:杀死并行进程
sh kill illegal number : Kill parallel process
我正在尝试使用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
正确的方法是什么?
谢谢。
您需要分别从每个进程中取回 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 + ";");
相关文章:
- boost::进程间消息队列引发错误
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 是否可以通过C++扩展强制多个python进程共享同一内存
- IPC使用多个管道和分支进程来运行Python程序
- 异常属于C++中的线程还是进程
- WMI检测进程创建事件-c++
- C++17中的并行执行策略
- 并行用于C++17中数组索引范围内的循环
- 如何在Elixir中调用递归函数并行
- OpenMP:并行更新数组总是需要减少数组吗
- c++多进程编写一个唯一的文件
- 如何在C++中将函数发送到另一个进程
- 如何使用OpenMP并行这两个循环
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 如何使用OpenMP并行化此矩阵时间矢量运算
- sh 杀死非法数:杀死并行进程
- 使用 c++ 的多线程和并行进程
- 下面的代码是否运行两个子进程,从 C++ 中的单个父进程并行执行
- 正在创建并行运行的多个子进程
- 进程(应用程序)的并行实例数