Thanks for your comments.
I need that because I have a multithreaded app in which a couple of threads are using almost all CPU. If I can trace in my log the ids of the threads I can identify which of them are causing trouble.
Also, if i have a deadlock, for example, I can check the log to see which thread is locked with which one.
Yes, in Linux pthread_self() gives something different that gettid().This returns the pid of the LWP associated with the threads. But ps -efL <pid> gives this same LWP id, so I can identify in my log which thread is doing something.
In MacOS, ps -M -p <pid> show the threads, but all with the same pid so is useless.
Thanks again.