16

On Linux ps -eLf | grep my-process-name gives a list of the threads within my process along with the TID of each thread.

On OSX ps -M pid gives me the list of the threads but does not show the TID of each thread.

How can I see thread TIDs under a single process from the command line?

Allen Luce
  • 7,859
  • 3
  • 40
  • 53

2 Answers2

10

You can't see the TIDs with the ps on Mac OS as you can experience while listing all the possible column options with ps L.

Anyway, if you dont mind exploring the threads as a root, you can use dtruss, which is primarily for processing syscall details, but it will at least show you the TIDs in the PID/LWPID (PID/THRD) column.

sudo dtruss -ap pid
katenoox
  • 1,072
  • 1
  • 14
  • 18
  • 2
    the output of dtruss doesn't show the pthread thread id, it shows a OSX-specific pointer id. converting between them is challenging – Erik Aronesty Oct 23 '19 at 21:13
3

Well, although I realize it may be considered sacrilegious to some, cross platform Powershell is now available for macOS, and it's pretty trivial to see thread ids with it. This will work:

Get-Process -Id 1234 | Select-Object Threads

It will spit back an object for each applicable thread that contains about 10 properties. One of them is 'Id'. You could also do:

gps -Id 1234 | select -Expand Threads | select -Expand Id

If you wanted to shorten the command up, and just get back the Ids.

Dharman
  • 30,962
  • 25
  • 85
  • 135
user2233949
  • 2,053
  • 19
  • 22