简体   繁体   中英

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.
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
You might also want to look further at the commands ps and pkill .
Note: I am assuming you are using a Linux OS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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