Re: Invisible threads in 2.6

From: Martin Zwickel
Date: Tue May 25 2004 - 02:04:14 EST


On Tue, 25 May 2004 02:21:19 +0000
lm240504@xxxxxxxxxxx bubbled:

> I've been experimenting with process/thread accounting in 2.6.x,
> and found this strange situation: if the leader thread of a multi-threaded
> process terminates, the other threads become undetectable. After the
> main thread becomes a zombie, /proc/<tgid>/task returns ENOENT on
> open. If you happen to know the TID, you can access /proc/<tid>/* directly,
> but otherwise, there is no way to observe the remaining threads, as far as
> I can see. Consider this program, for example:
>
> #include <pthread.h>
>
> void *run(void *arg)
> {
> for(;;);
> }
>
> int main()
> {
> pthread_t t;
> int i;
> for (i = 0; i < 10; ++i)
> pthread_create(&t, NULL, run, NULL);
> pthread_exit(NULL);
> }
>
> When I run it, the system (predictably) goes to ~100% CPU utilization,
> but there seems to be no way to find out who is hogging the CPU with
> top(1), ps(1), or anything else. All they can show is the main thread in
> zombie state, consuming 0% CPU.
>
> I'm not sure how to fix this (the pid_alive() test seems to be there for a
> reason), but it doesn't seem right. Any thoughts?

my kernel:
# cat /proc/version
Linux version 2.6.6-rc3-mm2 (root@phoebee) (gcc version 3.3.2 20031218 (Gentoo
Linux 3.3.2-r5, propolice-3.3-7)) #6 Fri May 7 10:56:06 CEST 2004

I just compiled your example and ran it:
# ./thread_test

# ps axw
...
12069 pts/175 S+ 0:00 ./thread_test
12070 pts/175 S+ 0:00 ./thread_test
12071 pts/175 R+ 0:06 ./thread_test
12072 pts/175 R+ 0:06 ./thread_test
12073 pts/175 R+ 0:06 ./thread_test
12074 pts/175 R+ 0:06 ./thread_test
12075 pts/175 R+ 0:06 ./thread_test
12076 pts/175 R+ 0:06 ./thread_test
12077 pts/175 R+ 0:06 ./thread_test
12078 pts/175 R+ 0:06 ./thread_test
12079 pts/175 R+ 0:06 ./thread_test
12080 pts/175 R+ 0:06 ./thread_test
...

# top
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
12072 root 25 0 83736 420 1380 R 12.1 0.1 0:16.94 thread_test
12075 root 25 0 83736 420 1380 R 12.1 0.1 0:16.93 thread_test
12073 root 25 0 83736 420 1380 R 11.0 0.1 0:16.92 thread_test
12074 root 25 0 83736 420 1380 R 11.0 0.1 0:16.92 thread_test
12076 root 25 0 83736 420 1380 R 11.0 0.1 0:16.82 thread_test
12077 root 25 0 83736 420 1380 R 11.0 0.1 0:16.87 thread_test
12078 root 25 0 83736 420 1380 R 11.0 0.1 0:16.84 thread_test
12071 root 25 0 83736 420 1380 R 9.9 0.1 0:16.95 thread_test
12079 root 25 0 83736 420 1380 R 7.7 0.1 0:16.80 thread_test
...

On my -mm patched kernel I can see them.

Regards,
Martin
--
MyExcuse:
piezo-electric interference

Martin Zwickel <martin.zwickel@xxxxxxxxxxxxxx>
Research & Development

TechnoTrend AG <http://www.technotrend.de>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/