 paul123
join:2000-11-03 Brookline, MA
| reply to dom6791 Re: Little Known Tips and Tricks...
Great idea for a thread. I'll start it off with one 
In unix, the way that an application programmer would normally query the kernel for kernel information is to use the ioctl() system call if there was not a C library call already available.
In linux, if you don't want to write a program or if you didn't have a utility already available (ie. uptime, ps, etc.) to query the kernel, there is a nice facility to access kernel information using a filesystem interface. This is the /proc interface. Most common modules in the kernel support this interface method.
For example, if you do a ls -al /proc, a lot of files are listed. Nearly all of them will have a zero byte count. But there is actually useful data in there .
cat /proc/meminfo will provide information on the kernel's view of memory. cat /proc/cpuinfo will provide information on the kernel's view of the cpu.
Ever wonder about specific process information? In the /proc interface, a directory is created for each process id that the kernel is currently running.
ls -al /proc/1 will provide all the information that the kernel is tracking for process 1 which is always the init process. For example, if you are curious what environment variables was passed to the init process when it started, cat /proc/1/environ.
If you don't have the uname application and you want to find the kernel version, cat /proc/sys/kernel/osrelease.
The /proc interface can be a useful method to query the kernel. |