Digit Oktavianto Web Log

Catatan Sampah si Digit

/proc Untuk Para Pemula Di Linux

| Comments

Saya mengambil tulisan ini dari internet, namun sayang sekali saya lupa dimana alamat web tersebut :( namun informasinya cukup berguna untuk bahan pengingat saya yang ahrus bolak-balik baca manual, jadi lebih baik di tulis kembali. :)

In this article I will talk about /proc which should be of interest to Linux newbies. I spent a couple of hours using “cat” to find system information. This is really slick. Just open a bash shell, su to root, and cd to /proc. Then it’s a simple matter of using the cat command to list all the info in the appropriate files.

Want to know how much memory you’re system is running on? How much is used and free? What kind of processor model/speed your system have? How about knowing exactly what occupies your pci slots? All that is in /proc including a ton of other system details.

The /proc filesystem is a direct reflection of the system kept in memory and represented in a hierarchal manner. The effort of the /proc filesystem is to provide an easy way to view kernel and information about currently running processes. As a result, some commands (ps for example) read /proc directly to get information about the state of the system. The premise behind /proc is to provide such information in a readable manner instead of having to invoke difficult to understand system calls.

The /proc fs can be used for system related tasks such as

  1. Viewing Statistical Information,
  2. Finding out HardwareInformation,
  3. Modifying Runtime Parameters,
  4. Viewing and Modifying Network Host Parameters
  5. Memory and Performance Information

Now with the definition out of the way, let’s start with the examples:

Print System Information

$ cat /proc/cpuinfo - Information about the processor, such as its type, make, model, and performance.

$ cat /proc/devices - List of device drivers configured into the currently running kernel.

$ cat /proc/filesystems - Filesystems configured into the kernel.

$ cat /proc/interrupts - Shows which interrupts are in use, and how many of each there have been.

$ cat /proc/ioports - Which I/O ports are in use at the moment.

$ cat /proc/meminfo - The number of total, used and free bytes of memory and swap area(s)

$ cat /proc/loadavg - Average of system load for the last 1, 5 and 15 minutes.

$ cat /proc/uptime - Time in seconds since boot-up and total time used by processes

$ cat /proc/version - Current rev of the kernel and/or distribution

$ cat /proc/environ - The process environment variables

$ cat /proc/mounts - Shows mounted filesystems. Shows device, mount point, filesystem type, permissions.

$ cat /proc/pci - Current occupation of pci slots.

Some proc files can be used to adjust settings in the kernel. This is especially true for files in the /proc/sys/ subdirectory. Some examples to change a setting temporarily on your system:

$ sudo echo abc > /proc/sys/kernel/hostname - This changes your server hostname to abc.example.com

$ sudo echo example.com > /proc/sys/kernel/domainname - This sets a domain name if you don’t have arleady or changes to a new one.

$ sudo echo Windows > /proc/sys/kernel/ostype - If you want to have some fun, you can change this to print Windows instead of Linux on your boot prompt.

$ sudo echo “Version 0.0.1” > /proc/sys/kernel/osrelease - Another neat trick to confuse your users.

There is a utility called sysctl – This tool is used to manipulate kernel parameters. If you type sysctl -a | more, you’ll see a long list of kernel parameters. You can use sysctl to modify these parameters. Only root has access to update.

This is Part 1 of /proc file system. There are many cool data /proc can provide to help troubleshoot or simply compile data about your server and operating system. In the next part of this article, I will explore a bit more advanced directories and kernel manipulation. I will also briefly touch on utilizing /proc fs as a programming tool. WARNING: Be sure to avoid viewing the kcore file in /proc. This virtual file contains an image of the kernel’s memory, and the contents of the file will do strange things to your terminal. In general, do not view any file unless you’re sure what it does.