Thread count of process x

applescriptunix

My AppleScript needs to get thread count of process x.

I have tried many ps etc codes but all these are not working for some reason.

I tried these:

do shell script "ps uH p 301 | wc -l" -->"       0"
do shell script "ps axo pid,ppid,rss,vsz,nlwp,cmd" --> error "ps: nlwp: keyword not found

Best Answer

ps on OS X takes different options than ps on Linux. Please have a look at man ps to see the detailed list of supported keywords. For threads I found the following (but I don't know whether this is the information you are looking for):

 wq         total number of workqueue threads
 wqb        number of blocked workqueue threads
 wqr        number of running workqueue threads

PS: I would recommend to first test any unix level commands in Terminal/bash and only move to AppleScript once they are working as expected. You are far more flexible in bash and also may get better/more helpful error messages back.