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
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.