打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
linux

Use a process group so as to enable sending a signal to all the process in the groups. For that, you should attach a session id to the parent process of the spawned/child processes, which is a shell in your case. This will make it the group leader of the processes. So now, when a signal is sent to the process group leader, it's transmitted to all of the child processes of this group.

Here's the code:

import osimport signalimport subprocess# The os.setsid() is passed in the argument preexec_fn so# it's run after the fork() and before  exec() to run the shell.pro = subprocess.Popen(cmd, stdout=subprocess.PIPE,                        shell=True, preexec_fn=os.setsid) os.killpg(pro.pid, signal.SIGTERM)  # Send the signal to all the process groups
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
jBPM4常见概念
编写linux守护进程
Linux Daemon Writing HOWTO
還在學: Linux Note: daemon 與 background process 的差異
python 判断linux进程,并杀死进程
linux下Ctrl+C信号处理
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服