OSX - How can I see the TID of all threads from my process?
Asked Answered
M

2

17

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?

Moustache answered 20/1, 2015 at 14:21 Comment(0)
B
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
Breathe answered 20/1, 2015 at 21:22 Comment(1)
the output of dtruss doesn't show the pthread thread id, it shows a OSX-specific pointer id. converting between them is challengingLinnealinnean
T
4

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.

Tetrapterous answered 28/7, 2021 at 17:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.