Skip to contentSkip to conversation

Status field in ps output for threaded programs in 2.6 kernel

DISCUSSION Albert Cahalan 1 participant 1 message May 13, 2004

lore
Share & tools
lore
#0 lore raw
Quoted 8 lines · Mihai Rusu
Quoted 3 lines · Nikita V. Youshchenko

Looks like kernel bug: displayed status of threaded process should not be "S" if some threads are active. And CPU usage statistics should correspond to all threads.

Hmm I dont know about that. A "solution" here is to have top also display threads (like ps -m or ps -H of a recent procps distro).

First of all, "ps -H" does a process tree display. You want one of these:

ps m    Tru64 BSD style, with threads after process
ps -m   Tru64 SysV style, with threads after process
ps H    FreeBSD style, with loose threads (independent sorting)
ps -L   Sun style, with grouped threads and LWP column
ps -T   SGI style, with grouped threads and TID column

For process state, maybe have the kernel spit out a '*' if not all threads are in the same state?

For CPU usage, Linux has been totally broken since day 1. The SUSv3 and POSIX standard requires that the OS report some notion of recent CPU usage. Linux doesn't bother. BSD provides a decaying average, like a per-process load average. AIX provides a simple average over a few seconds. SysV provides something similar.

Here is what Solaris does:

You get both per-process and per-thread data. It is provided as a fixed-point decaying average, with a 15-bit fraction. Thus:

0x8000 100%

0x6000   75%
0x4000   50%
0x2000   25%

0x0000 0%

With Linux, you get only the %CPU over the whole life of the process. So a process that runs for months using only 1% of the CPU will still appear to use 1% of the CPU even after it gets stuck in a CPU-eating loop. You can get around this by using "top", which is able to compute a real %CPU from one refresh to the next.