ProcFS
The /proc file system is yet another special file system. It presents
information about running processes as files. Typically, the files are read
and parsed by the program top
to get a summary of what is going on in a
system.
Each running program has a directory in the top-level directory corresponding to its Process ID (PID). The kernel itself has a PID of zero, and must be considered different from other programs since its entries do not necessarily make sense or contain complete information.
Entries
Each process/directory contains the following entries:
-
state
: The current state of the program. May be Running (0), Blocked (1), Zombie (2), Sleeping (4), Stopped (8), Deferred (16) or Crashed (15). This field is a bitmask, in some cases a process may be in a combined state. See thetop
program for more information. -
priority
: The current scheduling priority. Valid values are (0) for maximum priority, (1) for medium priority (default) and (2) for low priority (typically only used by the idle thread). -
sigmask
: The signal mask of the process written out as a signed integer. A value of one means that the corresponding signal is to be accepted by the process. -
sigpending
: Similar to the signal mask, however a set bit here means that a signal is set to be delivered, but the signal has not yet been delivered. Bits may be observed set if a signal is sendt while the process is already processing a signal. -
mpuregs
: The current set of MPU registers used by the program. These may be parsed to figure out what memory the program has access to. Each line in the output correspond to one MPU region, with the first being therbar
and the second beingrasr
. Check the Cortex-M3/4/7 manuals for how to parse these registers. -
cpu
: Contains four unsigned integers (32-bit) written out as signed integers. The first three are accumulators for CPU time in cycles spent in user mode, kernel mode and IO-operations. The last value is the maximum CPU clock. In order to calculate CPU time percentage, sample this file at a regular interval. Take the difference between the previous values and divide by the maximum CPU clock times the sampling interval. Note: Some kernel time is currently incorrectly accounted as user time. The IO time is the time spent processingread
,write
,fcntl
andioctl
calls. -
ownerpid
: The process ID of the parent process. -
gid
: The Group ID (GID). Same numerical value as the PID of the "main" program in the group. -
cwd
: Current working directory. -
fd
: A list of open file descriptors in the program. Contains the following columns: The first column is the file descriptor as seen by the program. The second column is the global file descriptor index as seen by the kernel. Identical values means that the file descriptors refer to the same file, even across processes. The third column is the mount point of the containing file system. The fourth column is the name of the file within that file system. Note that only the DevFS file system supports this feature at the moment. -
exe
: Path to the executable. Limited to 32 characters.
Considerations for the Kernel (PID 0)
Most of the entries apply to the internal init/startup thread of the kernel,
which will be blocked at nearly all times. Since it is a privileged kernel
thread the mpuregs
entry will be empty. Kernel memory usage must be estimated
by other means.