Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Process/Thread Monitoring

Currently i can list my processes with a simple python script:

import os os.system("Tasklist")

I would like to list all the threads associated with those processes, if any. The count of threads per process might be sufficient.

Would someone direct me where i might find this information.

Thank You.

like image 204
Huskeraider Avatar asked Nov 20 '25 10:11

Huskeraider


1 Answers

You can use the psutil module (download here) for cross-platform process information delivery.

After installing, 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]'
like image 70
enderskill Avatar answered Nov 21 '25 23:11

enderskill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!