2002-10-17 02:59:17

by Albert D. Cahalan

[permalink] [raw]
Subject: per-process %CPU

> I want to do following
>
> [root@server13 root]# ps -eo pid,%cpu,%mem,user,args --sort user hC
> ps: error: Option C is reserved.
> usage: ps -[Unix98 options]
> ps [BSD-style options]
> ps --[GNU-style long options]
> ps --help for a command summary
>
> but If I replace C by any other OUTPUT MODIFIERS it works.
> I just want the current %cpu of the process and not the
> decaying average, so is there an other way to get to my goal?
>
> I tried it on redhat, suse and debian distris ... always the same.

I have bad news for you. The kernel doesn't even maintain
the decaying average. Per-process %cpu on Linux is a lie,
and always has been -- except with "top", which crudely does
a measurement itself.

What you get for %cpu is calculated over the lifetime of
the process. Maybe you can find a scheduler hacker to fix
this problem. I'll Cc: a few for you.

Guys, this is a POSIX and UNIX requirement. The system is
supposed to report per-process %CPU for a "recent" time frame.