简体   繁体   English

杀死子进程,并在没有psutil或子进程的情况下获取子进程pid

[英]Killing child processes, and getting child processes pid without psutil or subprocess

我现在遇到了很多的这个问题,我想杀死我的所有子进程不会破坏我自己的进程或杀死一些组的所有进程或得到所有的子进程PID ......而这一切,而无需使用subprocess或python中的psutil库,任何人都不知道如何

If you really cannot access those libraries, you can use os if push comes to shove. 如果您确实无法访问这些库,则可以在推入时使用os
For example: 例如:

my_pid = os.popen('ps --no-headers -C name_of_process').read(5)
if my_pid != "":
    my_pid = int(my_pid)
    os.kill(my_pid, signal.SIGTERM)

'name_of_process' would be the name of your executable 'name_of_process'将是您的可执行文件的名称
You might also want to look further at the commands ps and pkill . 您可能还想进一步查看pspkill命令。
Note: I am assuming you are using a Linux OS 注意:我假设您使用的是Linux操作系统

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

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