Previous Section  < Day Day Up >  Next Section

Recipe 5.4. Getting Live Hardware Snapshots with /proc

5.4.1 Problem

You want to monitor a running system in real time, and view things like physical memory and CPU information, or identify drives.

5.4.2 Solution

Read the /proc virtual filesystem. Use only cat to read /proc, or utilities designed expressly for it, such as sysctl, lspci, ps, and top. The syntax is the same as for reading any file:

$ cat /proc/filename

You can explore /proc just like any filesystem and easily find the information you want. Look to the named folders for hardware information:

$ ls  /proc

bus  cmdline  cpuinfo  devices  dma  driver  filesystems  ide  kcore  kmsg  ksyms  loadavg

  meminfo  misc  modules  mounts  mtrr  partitions  pci  scsi  swaps  sys  tty

For example, to show CPU information, use:

$ cat /proc/cpuinfo

processor       : 0

vendor_id       : AuthenticAMD

cpu family      : 6

model           : 3

model name      : AMD Duron(tm) Processor

stepping        : 1

cpu MHz         : 801.442


To show physical memory and swap usage, use:

$ cat /proc/meminfo

total:    used:    free:  shared: buffers:  cached:

Mem:  262746112 237740032 25006080        0 11575296 150138880

Swap: 534601728 81661952 452939776

MemTotal:       256588 kB

MemFree:         24420 kB


To tell all about an IDE hard drive, use:

$ cat /proc/ide/via

-------VIA BusMastering IDE Configuration---------

Driver Version:                     3.37

South Bridge:                       VIA vt82c686a

Revision:                           ISA 0x22 IDE 0x10

Highest DMA rate:                   UDMA66

BM-DMA base:                        0xd400

PCI clock:                          33.3MHz


To see disk geometry, both real and logical, use:

$ cat /proc/ide/ide0/hda/geometry

physical     39870/16/63

logical      2501/255/63

To identify a drive, use:

$ cat /proc/ide/ide0/hda/model


To show driver versions for all IDE drivers, use:

$ cat /proc/ide/drivers

de-scsi version 0.93

ide-cdrom version 4.59-ac1

ide-floppy version 0.99.newide

ide-disk version 1.17

ide-default version 0.9.newide

To show capabilities of CD drives, use:

$ cat /proc/sys/dev/cdrom/info

CD-ROM information, Id: cdrom.c 3.12 2000/10/18

drive name:             sr1     sr0

drive speed:            40      32


Can read multisession:  1       1

Can read MCN:           1       1

Reports media changed:  1       1

Can play audio:         1       1

Can write CD-R:         1       0

Can write CD-RW:        1       0

Can read DVD:           0       1

Can write DVD-R:        0       0

Can write DVD-RAM:      0       0

To show SCSI devices, using the following command. Note that it does not differentiate between devices attached to the SCSI bus and IDE devices using the SCSI-emulation subsystem. These are IDE CD drives:

$ cat /proc/scsi/scsi

Attached devices:

Host: scsi0 Channel: 00 Id: 00 Lun: 00

  Vendor: TOSHIBA  Model: DVD-ROM SD-M1202 Rev: 1020

  Type:   CD-ROM                           ANSI SCSI revision: 02

Host: scsi0 Channel: 00 Id: 01 Lun: 00

  Vendor: LITE-ON  Model: LTR-24102B       Rev: 5S54

  Type:   CD-ROM                           ANSI SCSI revision: 02

This following command is just plain fun and has absolutely no practical value. It requires a functioning sound system. Warning: it's noisy—this is the sound of your CPU in action. Ctrl-C stops it:

# cat /proc/kcore > /dev/dsp

For AMD Users

Since AMD went to "performance ratings," instead of plain ole gigahertz, CPU ratings can be confusing. Your shiny new Athlon 3200 won't appear in /proc/cpuinfo as "cpu MHz 3200"—instead, it will be something like 2800. You're not being ripped off; that's a result of how AMD chooses to rate the performance of their processors. In a nutshell, they claim that clock speed alone is not an accurate measure of performance, so they devised a different scale that more accurately reflects the CPU's true abilities. Visit for details.

On the other hand if your Pentium 3200 shows up in /proc/cpuinfo as a number other than 3200, there is a problem, because Intel uses the literal clock speeds.

5.4.3 Discussion

Disk geometry, as expressed by /proc or any other utility, is largely a fiction. Modern drives are far more complex than the old "heads sectors cylinders" model.

As mentioned earlier, to read /proc use only cat or utilities designed expressly for it, such as sysctl, lspci, ps, and top. Pagers like less and more give a different picture, because they re-read /proc with each page. And you don't want to use a text editor, or any utility with write powers, because you can mess up your system in a heartbeat.

5.4.4 See Also

  • proc(5)

    Previous Section  < Day Day Up >  Next Section