"Even LINUX Experts discovers new tricks!"
Dear Forum members ,
Have you ever wandered how the "KDE System Guard ", "top" etc. actually works ? How it gets all the details information ?
Have you ever wanted to create a your own one ?
Now you can do it. Because all the information resides in human readable format in "/proc" directory.
Try doing a "ls /proc" in shell. You will get the following files describes below and some folders. The "PROC" folder is created and modified in runtime by kernel or some system processes. It contains all the information needed to do administrative job. In Windows environment it is very difficult to get all information, but in Linux it's a breeze .
Below is the relavent information about it's files in short , informations regarding directories is given next to it :=>
1) Available files (may be changed ,depending upon Linux version and installed programs!)
file:/proc/cmdline == Kernel Command line (eg . "/rhgb", "quite" etc.
file:/proc/cpuinfo == used cpus and various info about them
file:/proc/crypto == current password encription (such as MD5)
file:/proc/devices == available character(eg terminal,sound etc.) and block device name and corresponding number
file:/proc/diskstats == status about all diskdevice including ramdrive (such as free space,etc.)
file:/proc/dma == dma status (such as cascade)
file:/proc/execdomains == don't know, maybe about kernel domain !
file:/proc/fb == maybe about any pending mails
file:/proc/filesystems == available filesystems (such as : ext3,vfat,etc.)
file:/proc/interrupts == available and usable interrupts and their number
file:/proc/iomem == kernel ram info (may be about available memory mapped io space)
file:/proc/ioports == available system io ports (such as timer,pci,vga+ , etc)
file:/proc/kcore == You can not access it as it is used by kernel itself
file:/proc/kmsg == Kernel Messages
file:/proc/loadavg == CPU Loads and uptime
file:/proc/meminfo == details about memory , including swap,cache,physical memory size and available free space
file:/proc/modules == loded kernel modules (such as snd,alsa,hw,gameport etc.)
file:/proc/mounts ==mounted partitions
file:/proc/partitions == Available Disk Partitions (eg. hda,hda1,...,hdb,.. etc.)
file:/proc/pci == pci devices and their corresponding Bus no.,devive no.,function no. ,irq no. etc.
file:/proc/stat == cpu usage info , Includes per cpu load (eg. cpu0,cpu1,...) , context switches , uptime etc.
file:/proc/swaps == Swap partition drive name and size etc.
file:/proc/uptime == Uptime (times elapsed since boot) for individule cpus
file:/proc/version == Linux Kernel version and compiler used to build it
file:/proc/vmstat == Details Virtual memory Info ,including page faults,range,etc.
you can see individual files using command
Such as to view information about cpu issue command:
2) Available directories (it will certainly be deferrent in your pc!)
The directories with all number such as 1, 4567,2385,112,40,41 etc. are actually PID of the currently Running processes.
Start the default process viewer (in KDE you can try key combination of CTRL+ESC) , see the PID tag list and compare it with the directory listing of the "/proc" directory . You can certainly find similarity in between them. And YES those are the actually PID of those running processes! e.gThe folder having name 1 represents "init" process .
in my pc it is like this :==>
1 2366 2621 3451 3691 3844 9 ide pci
1139 2397 2693 3456 3693 39 acpi interrupts scsi
114 2439 27 3553 3699 3955 asound iomem self
192 2450 2712 3581 37 3997 buddyinfo ioports slabinfo
193 2463 2731 3614 3701 3998 bus irq stat
195 2486 2744 3615 3702 4 cmdline kcore swaps
196 2508 2755 3658 3705 40 cpuinfo kmsg sys
2 2527 28 3661 3706 4084 crypto loadavg sysrq-trigger
209 2537 2893 3663 3712 4089 devices locks sysvipc
2128 2548 3 3666 3713 41 diskstats mdstat tty
2132 2578 3019 3668 38 4192 dma meminfo uptime
2143 2579 3020 3678 3809 4193 dri misc version
2154 2591 3021 3680 3810 4254 driver modules vmstat
2174 26 3022 3682 3811 5 execdomains mounts
2208 2603 3023 3686 3812 6 fb mtrr
2325 2617 3024 3688 3813 7 filesystems net
2355 2619 3025 3689 3814 8 fs partitions
Enter a directory ,let it be "1" , so issue "cd 1", you will be now in folder 1.
view it's contains "ls" :=>
attr cmdline environ fd mem root statm task
auxv cwd exe maps mounts stat status wchan
Explanation of individuals
attr == its a folder containing attributes of all child and parent processes
cmdline == it contains the COMMAND LINE used to create the process , so you can get NAME of the process from here
environ == ENVIRONMENT variable passed to it
fd == its a folder containing file descriptor (opened file handle ?)
mem == memory info ?
root == its a folder link to root directory
statm == memory status ?
task == its a folder containing task number ? (same as it's PID)
auxv == ??
cwd == current working directory
exe == MEMORY IMAGE of the Process . SO YOU CAN DUMP IT EASILY IN RUNTIME , use it for debugging purpose!
maps == ??
mounts == currently mounted devices(mount it used to join different filesystem to root filesystem)
stat == status about the process containg fields such as NICE value,PID,VMsize,Process name etc. (*** Good for making own process information program as it contains all necessary fields****)
status == some of the info from "stat" file but in easily understandable format!
wchan == currently running thread ?
[ LEGENDS : "?" => doubtful ,check it in the internet, "??" => not known to me! ]
Lengthy isn't it ? but it will be comfortable when you get used to it. Keep it's copy locally.
Note to programmers
Now you know the secret of those programs . Why don't you try it ?
Let me know what you have discovered , email me at : email@example.com
Read data over and over and you will get the recent status , Linux will update it regularly.(so you don't have to be bothered with updation of "/proc" data.) You just have to update the GUI or text interface of your program according to the data provided.
******* Don't keep the files opened for longer as Linux writes to it at regular interval , may cause hang. Close the file as soon as you read it's contains *******
DONT TRY TO CHANGE "/proc" s CONTAINS AS IT MAY CAUSE UNEXPECTED RESULT!
Please pardon my mistake if it is done as I am not a "LINUX GURU" .
(PLEASE DONT ASK FOR HELP OR SOURCE CODE OR ANY OTHER THINGs )
(THE AUTHOR ASSUMES NO RESPONSIBILITY ABOUT THE CONTAINS OF THE ABOVE WRITTEN INFORAMTION, NOT ACCEDENTAL OR RESPONSIVE OR ANY OTHER MEANS. USE IT AT YOUR OWN RISK)