7

I'd like to be able to get the number of thread per process in command-line and get the exact same number I can see via the Activity Monitor.

At the moment the IntelliJ IDEA process (PID 5235) has 266 Thread. I'd like to get this number but via a command line.

I've tried

lsof -p 5235 | wc -l

Any suggestions?

TheEwook
  • 188

3 Answers3

14

Try the following:

NUM=`ps M <pid> | wc -l` && echo $((NUM-1))

We subtract 1 from the line count because ps outputs a HEADER in the 1st line.

jweyrich
  • 1,386
3

This also works:

ps M <pid> | wc -l
Greenonline
  • 2,390
giraysam
  • 131
2

One can also engage tail command in order to cut off header line in the ps M output, e.g:

ps M <pid> | tail -n+2 | wc -l

where -n+2 option means "get all lines starting from the second one"