Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

reading /proc/<pid>/usage multiple times - what are the rules?

807567Jun 7 2010 — edited Jun 7 2010
The proc(4) man page contains this warning:

Although process state and consequently the contents of
/proc files can change from instant to instant, a single
read(2) of a /proc file is guaranteed to return a sane
representation of state; that is, the read will be atomic
with respect to the state of the process. No such guarantee
applies to successive reads applied to a /proc file for a
running process.

Does this mean that I must open each /proc file each time I want to get a guaranteed sane representation of the data?

My program (64 bit, built on SPARC Solaris 9, run on Solaris 10) currently opens /proc/<pid>/usage and reads from the file descriptor every 1 second or so. I occasionally see weird data where pr_utime and pr_stime decrease in value. Sometimes the decrease is only for 1 sample and other times the decrease is permanent. I'm wondering if I should be closing and opening the /proc file every time? That seems quite expensive when monitoring thousands of processes.

Thanks in advance for any help provided.

Norm Green
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2010
Added on Jun 7 2010
1 comment
1,527 views