htop icon indicating copy to clipboard operation
htop copied to clipboard

support threads on OSX

Open robaho opened this issue 6 years ago • 8 comments

It's a bit rough, because the OSX thread ID is not a PID, but it does work.

robaho avatar Oct 31 '18 03:10 robaho

Thank you! This is working as advertised! (macOS Mojave)

It does, however, need sudo htop so threads are shown.

Kronuz avatar Nov 20 '18 21:11 Kronuz

Yes, in order to remove the sudo requirement, there is another OSX API that needs to be used, and the application needs to be signed - possible but a lot more work in the build/packaging phase

robaho avatar Nov 21 '18 00:11 robaho

Hi robaho! This is exciting, thanks! Do you know what that other API you mentioned is, by chance (the one that requires signing)?

joshuawarner32 avatar Dec 01 '18 00:12 joshuawarner32

@joshuawarner32 not really a different API, but a different process. see http://os-tres.net/blog/2010/02/17/mac-os-x-and-task-for-pid-mach-call/

It is probably easier to set the setuid bit on the executable like 'top' does.

robaho avatar Dec 01 '18 01:12 robaho

Oh, hmm... based on my (brief, incomplete) testing, it looks like calling task_for_pid requires SIP to be disabled, even when running as root. I didn't try a setuid bit, but I'd be a little surprised if that had different behavior.

Signing could probably work - but having people install a self-signed code signing cert sounds kinda sketchy.

joshuawarner32 avatar Dec 03 '18 16:12 joshuawarner32

The code uses task_for_pid now and I don’t have SIP disabled and it works for me.

robaho avatar Dec 03 '18 17:12 robaho

Ah, interesting. I was testing against Google Chrome, which seems to have some additional anti-debugging protections enabled, and does require disabling SIP before listing the threads. When I try other processes on my system, they generally work fine.

joshuawarner32 avatar Dec 03 '18 22:12 joshuawarner32

Yea, it certainly isn’t easy to find official docs on this stuff, probably intentionally.

robaho avatar Dec 03 '18 23:12 robaho