Without practice this lib (backend)..
I don't know is it help you ,
ps -AT giving all identifier , if i remember with my old head now...
(right is (fork (pid) repeated line) left is (sub) thread , ipc ....)
To decrease bottom level side learning:
read source utility ps and extract function just necessary for you
Strange that this function is not already existing with this lib ??
It would be possible to wrong the origin process with that you operate two side ...
For tagging threads I use Thread Local Storage to contain a cardinal thread number.
Staticly initialize the variable with -1, then when you want the ID test value of TLS id variable, if .lt. 0 atomic incriment a variable used for the next ID and take the prior value (or incrimented value) and insert into the TLD id variable. Something like the following untested code.
__declspec(thread) long myThreadID = -1;
volatile long myNextThreadID = 0;
inline long getMyThreadID()
if(myThreadID >= 0)
myThreadID = InterlockedExchangeAdd(&myNextThreadID, 1);
return myThreadID ;