/proc/PID/stat documentation?

A

Alex Young

Not strictly a Ruby question, but I figure someone around here will know
the answer...

I'm using the sys-proctable gem to gather process load information on a
Debian machine (kernel 2.6.15 if it's relevant), because I'm trying to
do some load-balancing between machines and processes on those machines.
However, I can't seem to find any documentation on what the numbers
returned actually represent - specifically, the units of the utime,
stime, cutime and cstime fields, and precisely what they represent.

The numbers are lifted straight from /proc/PID/stat, so any
documentation on that would be handy. I've checked the documentation in
the kernel source tree, but it was singularly unenlightening - unless I
missed something.

For example:

-- konsole_ps.rb --

require 'proctable'
require 'yaml'
konsole = Sys::procTable.ps.find{|p| p.name == 'konsole'}
y({'utime' => konsole.utime, 'stime' => konsole.stime, 'cutime' =>
konsole.cutime, 'cstime' => konsole.cstime})

-- output --
---
cutime: 0
utime: 82
stime: 9
cstime: 0

I don't understand what the numbers that come out represent, and I can't
really tie them up with what comes out of `ps`. Can anyone point me in
the right direction?
 
S

Sylvain Joyeux

Try "man 5 proc", but I'm afraid it should be more or less the same
information than in the kernel docs ...

Sylvain Joyeux
 
C

Cian

Try "man 5 proc", but I'm afraid it should be more or less the same
information than in the kernel docs ...
Yep, the proc(5) manpage explains what the *time variables mean.

The units are 'jiffies', which appear to be Linux kernel scheduler run
time intervals. There's an explanation of what jiffies are at

http://kerneltrap.org/node/6857

Cian
 
M

M. Edward (Ed) Borasky

Alex said:
Not strictly a Ruby question, but I figure someone around here will
know the answer...

I'm using the sys-proctable gem to gather process load information on
a Debian machine (kernel 2.6.15 if it's relevant), because I'm trying
to do some load-balancing between machines and processes on those
machines. However, I can't seem to find any documentation on what the
numbers returned actually represent - specifically, the units of the
utime, stime, cutime and cstime fields, and precisely what they
represent.

The numbers are lifted straight from /proc/PID/stat, so any
documentation on that would be handy. I've checked the documentation
in the kernel source tree, but it was singularly unenlightening -
unless I missed something.

For example:

-- konsole_ps.rb --

require 'proctable'
require 'yaml'
konsole = Sys::procTable.ps.find{|p| p.name == 'konsole'}
y({'utime' => konsole.utime, 'stime' => konsole.stime, 'cutime' =>
konsole.cutime, 'cstime' => konsole.cstime})

-- output --
---
cutime: 0
utime: 82
stime: 9
cstime: 0

I don't understand what the numbers that come out represent, and I
can't really tie them up with what comes out of `ps`. Can anyone
point me in the right direction?
utime is the amount of time spent in user mode. If it's being
accumulated correctly, it will include time from both user and "nice"
mode. stime is the amount of time spent in system or kernel mode. If
it's being accumulated correctly, it will include system, irq and
softirq time.

cutime and cstime are the cumulative values of utime and stime,
respectively. When a process forks (clones) a child process (thread),
said child accumulates its own utime and stime. When the process exits,
its accumulated utime gets added back into the parent's cutime, and its
stime gets added back into the parent's cstime. Have a look at the
values for cutime and cstime for the "init" process -- they will be huge
because a parentless process cannot exist -- if a process's parent dies,
"init" adopts it. :)

Now on to "ps". "ps" lives in the "procps" package. It, for some reason,
lumps system and user time together. "ps" converts (utime+stime) to TIME
and (cutime+cstime) to CTIME. It shouldn't do that, but it does and IIRC
the developer of "procps" flat out refuses to change it. "top" is also
in "procps".

One final note: if you really need to know the next layer of detail down
to manage your server, send me an email off list and I'll point you to
some resources. I've never really seen a lot of documentation on this
other than the excellent O'Reilly book, "Understanding The Linux
Kernel", which isn't really written for server managers. Most of the
other books either have just the "top" layer (pun intended) or are
written around a specific tool set.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top