Python: process / thread monitoring

I can currently list my processes with a simple python script:

import os os.system ("Tasklist")

I would like to list all threads associated with these processes, if any. The number of threads per process may be sufficient.

Will anyone guide me to where I can find this information.

Thank.

+3


source to share


1 answer


You can use the psutil module (download here) to deliver cross platform information.

Once installed, use the following code to get the thread count of any process id.



import psutil
for proc in psutil.process_iter():
    print proc.name+' ['+str(proc.get_num_threads())+' threads]'

      

+3


source







All Articles