in reply to Get PID of child threads
Both top and htop will toggle the display of PID/TID when you press 'H'. The header, somewhat confusingly, remains "PID". In reality, the PID is shared between threads. The ps utility has a separate field for thread ID, called "LWP". In any case, this ID is accessible for the thread via gettid, a Linux-specific syscall...
Here's a snippet that appears to work on my system:
use threads; sub gettid { use Config; die if $Config{archname} !~ /x86_64-linux/; syscall 186 } sub diag { print "pid=$$ tid=@{[threads->tid]} gettid=@{[gettid]}\n"; } async { diag }->join for 1..5;
Edit. s/detach/join/, just in case.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Get PID of child threads
by TS90 (Novice) on Apr 03, 2017 at 22:29 UTC |