psutil module in python -


i newbie in python , trying understanding of psutil module. question if have more 1 instance of process (e.g. 2 instances of vlc media player), psutil.kill() kills instances of process or 1 of instances?

no. kill method called on process object, question of finding right process. might iterate through them:

for proc in psutil.process_iter(): try:     print("{:4d} {:4d} {:s}".           format(proc.pid, proc.ppid, proc.exe)) except psutil.accessdenied:     pass except psutil.nosuchprocess err:     print("****",err)  

the example exception handling handle race conditions - process might finish between finding , interrogating it. issue identifying correct process wish kill. typically use process id, pid, or maybe cmdline. if wish kill instances, use exe.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -