Huskeraider
Huskeraider

Reputation: 89

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.

Upvotes: 3

Views: 4249

Answers (1)

enderskill
enderskill

Reputation: 7674

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]'

Upvotes: 4

Related Questions