I am a newbie in python and trying to get an understanding of psutil
module. My question is that if have more than 1 instance of a process (e.g. two instances of VLC media player), does psutil.kill()
kills all the instances of that process or only one of the instances?
No.
kill
is a method called on a process object, so it is a question of finding the right process. You might iterate through them:The example exception handling is to handle race conditions - the process might finish between finding it and interrogating it. The issue is identifying the correct process you wish to kill. Typically you would use the process ID,
pid
, or maybecmdline
. If you do wish to kill all instances, then useexe
.