ARTICLE

Procfs from the inside
Contributed by Fernando Apesteguia in Misc on 2006-03-20 14:59:21
Page 4 of 5 /p>

Some examples on using procfs

Procfs is a very useful file system. You can gather a lot of information from it without worrying about libraries, or system calls or writing C programs. Just reading files.We have seen how procfs works from the inside. Let’s see what can we do with its files:

System temperature:

[fernape@Hammer]$ while true;
> do cat /proc/acpi/thermal_zone/THRM/temperature ;
> sleep 5;
> done;

You can easily change the script above to read /proc/acpi/battery/BAT0/state to know your battery charge. Isn't this easier than writing a C program?

Change host and domain names:

Certain files under /proc are available for writing (only for root). You can change hostname and domain name by writing in:

/proc/sys/kernel/domainname and /proc/sys/kernel/hostname

Please, take care. Change the host and domain name is not a dangerous task, but with procfs you can change a lot of settings than can lead to a lack of performance.

See the kernel boot parameters:

You can see them in cmdline.

[fernape@Hammer proc]$ cat cmdline
ro root=LABEL=/1 rhgb quiet console=tty0

These are only a few examples. With procfs you can set the maximum number of waiting RT POSIX signals, the number of semaphores the system can manage, the maximum number of files opened by the kernel, etc. And procfs can be a good allied in program debugging.

If you want to read more about files in /proc you can read this excellent article: http://www.linuxforums.org/misc/understanding_/proc.html



Article Index
Procfs from the inside
OS basics: user-land vs. Kernel-land
Implementing procfs
Some examples on using procfs
Conclusions
 
Discussion(s)
Good information
Written by beparas on 2008-07-04 05:39:48
This is article contains good information.
Thank You
Discuss! Reply!