2005-01-07 00:28:34

by jesse

[permalink] [raw]
Subject: how to find all threads of a given process?

suppose I already know the PID of a process, how could
i quickly identify all threads of this process?

As i know, under /proc, threads of all processes have
prefix ".", one way is to iterate each one and do the
check. the approach is too expensive. any other
suggestions?

for instance,



2005-01-07 08:20:28

by David Blomberg

[permalink] [raw]
Subject: Re: how to find all threads of a given process?


jesse said:
> suppose I already know the PID of a process, how could
> i quickly identify all threads of this process?
>
> As i know, under /proc, threads of all processes have
> prefix ".", one way is to iterate each one and do the
> check. the approach is too expensive. any other
> suggestions?
>
> for instance,

wouldn't this be easier in user space using "ps H" then one of two options
happens depending on the use of fork and other issues (making the question
hard to answer as stated) either A: they will all have the same PID or
B:they will all have varying PIDs in the later case you could use looks
for all PIDs sharing the same ancestor PPID (depending on how far down you
are in the fork list)

2005-01-07 11:58:48

by Miquel van Smoorenburg

[permalink] [raw]
Subject: Re: how to find all threads of a given process?

In article <[email protected]>,
jesse <[email protected]> wrote:
>suppose I already know the PID of a process, how could
>i quickly identify all threads of this process?

With 2.6 and NPTL, you'll find them under /proc/PID/task

>As i know, under /proc, threads of all processes have
>prefix ".", one way is to iterate each one and do the
>check. the approach is too expensive. any other
>suggestions?

I've never seen anything like that. Is that a vendor-patched
kernel, something like Redhat 2.4 + NPTL support ?

Mike.