Understanding /proc

/proc is often considered one of the most mysterious parts of the linux file system.  For those comming from the windows world especially, but also those who have been using Linux for years, proc seems an at times incomprehensible web of mysterious files and directories.

Understanding the mysteries of /proc can greatly aid in administrering and programming on linux systems, because proc is itself a key into the depths of the system.  In some ways, proc can be thought of as similar to the windows registry; it contains specific files that contain information about the system, and control how the system operates.

There are two main ways that proc can be used: to monitor and keep track of processes, and to monitor and tune the kernel.

On the process side, proc has subdirectories for each currently running process.  The numeric directory entires in proc are PIDs representing the currently running processes.  Inside the directory for each PID are a number of useful files that can be used both from the command line to get information about a process, and, especially, from within the application in order to get useful information about itself.

Of particular note are:

  • cmdline: this contains the command used to launch the application
  • cwd: a simlink to the applications current working directory
  • exe: a simlink to the application running
  • status: contains useful information; especially useful for seeing memory usage

Outside of using proc to gain information regarding processes, proc also contains useful system information.  Of particular note are:

  • cmdline: contains the kernel boot parameters, useful for custom init scripts
  • cpuinfo: contains information about the processors or cores in the system
  • loadavg: contains the system load average
  • self: a simlink to the PID directory for the current process

Learning to effectively use proc can greatly ehnance the ability and ease with which you can tune your system, as well as allowing your applications to effectively manage and monitor themselves and other processes.

Leave a Comment

You must be logged in to post a comment.