11def kill_all ():
22 for proc in psutil .process_iter (['pid' , 'name' , 'username' ]):
33 try :
4- if ((proc .info ['username' ] == None )):
4+ if ((proc .info ['username' ] == None )): #If username is None then process will not be Killed
55 print ('skipped :' ,proc .info ['pid' ])
6- elif ((proc .info ['name' ] == None )):
6+ elif ((proc .info ['name' ] == None )):# Ignore this one
77 print ('skipped :' ,proc .info ['pid' ])
8- elif ('WindowsTerminal.exe' in proc .info ['name' ]):
9- print ('skipped 1 :' ,proc .info ['pid' ])
10- elif ('Qt5gui.exe' in proc .info ['name' ]):
11- print ('skipped 1 :' ,proc .info ['pid' ])
12- elif ('conhost.exe' in proc .info ['name' ]):
8+ elif ('conhost.exe' in proc .info ['name' ]):# Important file for windows
139 print ('skipped 2 :' ,proc .info ['pid' ])
14- elif ('msedge .exe' in proc .info ['name' ]):
10+ elif ('python .exe' in proc .info ['name' ]):# Python is Important
1511 print ('skipped 2 :' ,proc .info ['pid' ])
16- elif ('python.exe' in proc .info ['name' ]):
17- print ('skipped 2 :' ,proc .info ['pid' ])
18- elif ('explorer.exe' in proc .info ['name' ]):
19- print ('skipped 2 :' ,proc .info ['pid' ])
20- elif ('cmd.exe' in proc .info ['name' ]):
21- print ('skipped 2 :' ,proc .info ['pid' ])
22- elif ('sublime_text.exe' in proc .info ['name' ]):
12+ elif ('cmd.exe' in proc .info ['name' ]):# Running this script on what?
2313 print ('skipped 2 :' ,proc .info ['pid' ])
24- elif (psutil .users ()[0 ][0 ] not in proc .info ['username' ]):
14+ elif (psutil .users ()[0 ][0 ] not in proc .info ['username' ]):# Ignore this one too
2515 print ('skipped :' ,proc .info ['pid' ])
2616 else :
2717 print (proc .info )
28- #x=input('else : ')
2918 print ('killed' )
3019 proc .kill ()
3120 except Exception as e :
3221 print (e )
3322 pass
34- kill_all ()
23+ kill_all ()
0 commit comments