>>Single Point of Failure >>

§ Home § CV § Blog Photography Divagações §

Calendar

November 2009
M T W T F S S
« Sep   Dec »
 1
2345678
9101112131415
16171819202122
23242526272829
30  


Popular Tags


Recent Entries



Categories


Archives

CPU load average in /proc

Ξ November 8th, 2009 | → 0 Comments |
Development |, , |

One of my C/C++ applications needed to provide information about CPU usage for debug and monitoring purposes. I never had to do anything like this, but quickly found what something interesting. The getloadavg is a standard library function that provides simplified information on CPU load average.

Because the function seems to point to /proc as source of information, I got to “take a look under the hood” and search for more information about /proc. I already knew that this so called filesystem (which in fact is only virtual) provides an easily accessible interface to kernel information.

Inside, it contains a folder called pid for each process running in the machine and several other folders/files that contain information on available memory, devices (e.g. disks) or kernel version.

If you take the usual look at the man page for proc, I’m sure you’ll find it interesting. it contains much more information than the one I was expecting.

 

Emptying a file

Ξ November 8th, 2009 | → 0 Comments |
Tools |, , , |

To empty an existing file, without having to recreate it, one can simply

> file

There are other ways to do the same, but none of the them are as simple. One can

cat /dev/null > file
echo -n > file

If the goal is only to change the file access timestamp, them you can simply

touch file

 


On the nightstand...



Entries | Comments