You can find more detail about /proc filesystem on Linux.
The /proc directory is actually a pseudo-filesystem. The files in /proc mirror currently running system and kernel processes and contain information and statistics about them.

/proc/devices

$cat /proc/devices
Character devices:
  1 mem
  4 /dev/vc/0
  4 tty
  4 ttyS
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
...

/proc/interrupts

$cat /proc/interrupts
        CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       CPU6       CPU7       
  0:     129         0          0 3410936854          0          0          0          0   IO-APIC-edge      timer
8:       0         0          0          1          0          0          0          0   IO-APIC-edge      rtc0
  9:       0         0          0          2          0          0          0          0   IO-APIC-fasteoi   acpi
 16:       0         0          0          0          0          0          0   33138244   IO-APIC-fasteoi   ehci_hcd:usb1
 17:       0         0          0          0          0          0          0        421   IO-APIC-fasteoi   snd_hda_intel
...
/proc/partitions

$cat /proc/partitions
major minor  #blocks  name

   8        0  976762584 sda
   8        1     512000 sda1
   8        2  976248832 sda2
   8       16  976762584 sdb
   8       17  976760832 sdb1
... 

/proc/loadavg

$cat /proc/loadavg 
0.91 0.96 0.99 2/688 9577
/proc/meminfo

$cat /proc/meminfo
MemTotal:       16324032 kB
MemFree:          453740 kB
Buffers:          473016 kB
Cached:          5082896 kB
SwapCached:        84184 kB
Active:         11147752 kB
...

Shell scripts may extract data from certain of the files in /proc.

Check if ISO file system support in kernel

FS=iso 
grep $FS /proc/filesystems # iso9660

Check kernel version

kernel_version=$( awk '{ print $3 }' /proc/version )

Check CPU type, then do things properly

CPU=$( awk '/model name/ {print $5}' < /proc/cpuinfo )
if [ "$CPU" = "Pentium(R)" ]
then
run_some_commands
...
else
run_other_commands
...
fi

Get CPU speed

cpu_speed=$( fgrep "cpu MHz" /proc/cpuinfo | awk '{print $4}' )
# Current operating speed (in MHz) of the cpu on your machine.
# On a laptop this may vary, depending on use of battery
#+ or AC power.

Get a PID command line 

#!/bin/bash
# Get the command-line parameters of a process.
OPTION=cmdline
# Identify PID.
pid=$( echo $(pidof "$1") | awk '{ print $1 }' )
# Get only first instance of multiple instances

echo
echo "Process ID of (first instance of) "$1" = $pid"
echo -n "Command-line arguments: "
cat /proc/"$pid"/"$OPTION" | xargs -0 echo

Ouput looks like this

$./getcmd.sh xinetd

Process ID of (first instance of) xinetd = 2747
Command-line arguments: xinetd -stayalive -pidfile /var/run/xinetd.pid

Another USB device example:

devfile="/proc/bus/usb/devices"
text="Spd"
USB1="Spd=12"
USB2="Spd=480"
bus_speed=$(fgrep -m 1 "$text" $devfile | awk '{print $9}')
#^^^^ Stop after first match.
if [ "$bus_speed" = "$USB1" ]
then
echo "USB 1.1 port found."
# Do something appropriate for USB 1.1.
fi

Peripheral control
It is even possible to control certain peripherals with commands sent to the /proc directory.

root# echo on > /proc/acpi/ibm/light

This turns on the Thinklight in certain models of IBM/Lenovo Thinkpads. (May not work on all Linux distros.) Of course, caution is advised when writing to /proc.

Note: In general, it is dangerous to write to the files in /proc, as this can corrupt the filesystem or crash the machine.


The /proc directory contains subdirectories with unusual numerical names. Every one of these names maps to the process ID of a currently running process. Within each of these subdirectories, there are a number of files that hold useful information about the corresponding process. The stat and status files keep running statistics on the process, the cmdline file holds the command-line arguments the process was invoked with, and the exe file is a symbolic link to the complete path name of the invoking process. There are a few more such files, but these seem to be the most interesting from a scripting standpoint.

Finding the process associated with a PID
 
Either of them would work

find /proc/$1/exe -printf '%l\n'
Or
lsof -aFn -p $1 -d txt | sed -ne 's/^n//p'

Online connect status

#!/bin/bash
# connect-stat.sh
# Note that this script may need modification
#+ to work with a wireless connection.
PROCNAME=pppd
PROCFILENAME=status
NOTCONNECTED=85
INTERVAL=2
# ppp daemon
# Where to look.
# Update every 2 seconds.
pidno=$( pidof $PROCNAME )
#
# Moral of the story:
#+ When a command sequence gets too complex, look for a shortcut.
if [ -z "$pidno" ] # If no pid, then process is not running.
then
  echo "Not connected."
  exit $NOTCONNECTED
else
 echo "Connected."; echo
fi
while [ true ]
do
# Endless loop, script can be improved here.

if [ ! -e "/proc/$pidno/$PROCFILENAME" ]
# While process running, then "status" file exists.
then
echo "Disconnected."
#
exit $NOTCONNECTED
fi
netstat -s | grep "packets received" # Get some connect statistics.
netstat -s | grep "packets delivered"
sleep $INTERVAL
echo; echo
done
exit 0
# As it stands, this script must be terminated with a Control-C.