3

sysfs makes perfect sense -- it represents the system, and is mounted under /dev. procfs, which gets mounted to /proc, is much more nebulous however. What are procfs & /proc used for?

2
  • sysfs is mounted under /dev? Which version of Ubuntu are you referring to? Oct 13, 2010 at 20:35
  • @max: Perhaps I screwed that up -- it's been a long time since I've played with unix boxes. Oct 13, 2010 at 22:20

4 Answers 4

9

Historically (years before Linux), /proc came first, and contained one file per process. Each (pseudo)-file provided access to the memory of the process, e.g., reading byte number 0x1234 from the file gave you the contents of address 0x1234 in the process's virtual memory. This interface was used by commands such as ps (the original process information viewer) and debuggers.

Subsequent variants of Unix copied the principle, but not the details. For example, on Linux, there is one directory per process, containing various information in a readable form. For example /proc/1/cwd is a symbolic link to the current working directory of process 1, and /proc/1/cmdline is a file containing the command line arguments.

Because it was there, Linux also used /proc to provide system information, such as /proc/cpuinfo containing information about the CPU (microprocessor) and /proc/bus/usb/ containing information about USB devices. The documentation of /proc is in the kernel documentation in filesystems/proc.txt.

Later, /sys (the sysfs filesystem) came to provide information about the kernel. For example, there is information about USB devices under /sys/bus/usb (in a different format from /proc/bus/usb), and information about kernel modules (as well as interfaces to control some modules) under /sys/modules.

Note that /proc/sys is not the same thing as /sys. /proc/sys shows a specific set of runtime-configurable kernel parameters called sysctl parameters.

You will find more historical and current information about /proc on Wikipedia.

¹ or more precisely, the proc filesystem, which can be mounted in other locations (but not having it available at /proc will break a lot of programs).

7

/proc is a real-time api to the kernel. You can set kernel variables, or retrieve kernel information. procfs is analogically a file system simulation to be able to communicate with the kernel via the file system.

Each process has its own directory under /proc with the process id as the name. In this directory you can find all kind of information the kernel has for the particular process.

Other directories allow to either get kernel statistics (like /proc/meminfo) or information (like /proc/cpuinfo) or you can configure certain things (like /proc/sys/vm/swappiness allows you to change how the kernel will use the swap space).

3

procfs presents information about your running processes.

For example:

$ sleep 120 &
[2] 11581
$ ls /proc/11581
...
cmdline
cwd
...
$ cat /proc/11581/cmdline
sleep120
0

A bit of a variation on some answers.

/proc is a file-system representation of the currently running processes. You don't go anywhere special, if you can read files, you can interact with the kernel. procfs is just the implementation of that.

The philosophy here is: Use the small tools like grep and friends to interact with things like processes vs writing specialized tools to interact with processes.

1
  • Hm, about the philosophy: It is more like: use open/read/write syscalls to interact with processes etc. - e.g. Solaris has /proc as well but the content of the (virtual) files is not human readable and thus not directly usable via grep & co., i.e. there are system programs that use these files. /proc started as an innovation in the Plan OS - would be interesting to see what format they used in files under /proc Oct 13, 2010 at 20:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .