If you list the contents of the /proc
directory, you will see many directories where the name of the directory
is a number. These are the directories containing information on all
processes currently running on the system:
$ ls -d /proc/[0-9]* /proc/1/ /proc/302/ /proc/451/ /proc/496/ /proc/556/ /proc/633/ /proc/127/ /proc/317/ /proc/452/ /proc/497/ /proc/557/ /proc/718/ /proc/2/ /proc/339/ /proc/453/ /proc/5/ /proc/558/ /proc/755/ /proc/250/ /proc/385/ /proc/454/ /proc/501/ /proc/559/ /proc/760/ /proc/260/ /proc/4/ /proc/455/ /proc/504/ /proc/565/ /proc/761/ /proc/275/ /proc/402/ /proc/463/ /proc/505/ /proc/569/ /proc/769/ /proc/290/ /proc/433/ /proc/487/ /proc/509/ /proc/594/ /proc/774/ /proc/3/ /proc/450/ /proc/491/ /proc/554/ /proc/595/
Note that as a user, you
can (logically) only display information related to your own
processes, but not those of other users. So, login as root
and see what information is available from process 1, which is the
init process and is the one responsible
for starting up all other processes:
$ su Password: # cd /proc/1 # ls -l total 0 -r-------- 1 root root 0 Aug 15 18:14 auxv -r--r--r-- 1 root root 0 Aug 15 18:14 cmdline lrwxrwxrwx 1 root root 0 Aug 15 18:14 cwd -> // -r-------- 1 root root 0 Aug 15 18:14 environ lrwxrwxrwx 1 root root 0 Aug 15 18:14 exe -> /sbin/init* dr-x------ 2 root root 0 Aug 15 18:14 fd/ -rw-r--r-- 1 root root 0 Aug 15 18:14 loginuid -r--r--r-- 1 root root 0 Aug 15 18:14 maps -rw------- 1 root root 0 Aug 15 18:14 mem -r--r--r-- 1 root root 0 Aug 15 18:14 mounts -rw-r--r-- 1 root root 0 Aug 15 18:14 oom_adj -r--r--r-- 1 root root 0 Aug 15 18:14 oom_score lrwxrwxrwx 1 root root 0 Aug 15 18:14 root -> // -rw------- 1 root root 0 Aug 15 18:14 seccomp -r--r--r-- 1 root root 0 Aug 15 18:14 stat -r--r--r-- 1 root root 0 Aug 15 18:14 statm -r--r--r-- 1 root root 0 Aug 15 18:14 status dr-xr-xr-x 3 root root 0 Aug 15 18:14 task/ -r--r--r-- 1 root root 0 Aug 15 18:14 wchan #
Each directory contains the same entries. Here is a brief description of some of the entries:
cmdline
: this
(pseudo-)file contains the entire command line used to invoke the
process. It is not formatted: there are no spaces between the program
and its arguments, and there is no newline at the end of the line. To
view it, you could use: perl -ple 's,\00, ,g'
cmdline.
cwd
: this symbolic
link points to the current working directory (hence the name) of the
process.
environ
:
this file contains all the environment variables defined for
this process, in the VARIABLE=value
form. Similar to cmdline
, the output is
not formatted at all: no newlines separate the different
variables, and there is no newline at the end. One way to
view it: perl -ple 's,\00,\n,g'
environ.
exe
: this is a symlink
pointing to the executable file corresponding to the process being
run.
fd
: this subdirectory
contains the list of file descriptors currently opened by the process.
See below.
maps
: when
you print the content of this named pipe (with
cat for example), you can see the parts of
the process' address space which are currently mapped to a
file. From left to right, the fields are: the address space
associated to this mapping, the permissions associated to this
mapping, the offset from the beginning of the file where the
mapping starts, the major and minor number (in hexadecimal) of
the device on which the mapped file is located, the inode
number of the file, and finally the name of the file
itself. When the device is 0 and there's no inode number or
filename, this is an anonymous mapping. See mmap(2).
root
: this is a symbolic
link which points to the root directory used by the
process. Usually, it will be /
, but see
chroot(2).
status
: this file contains
various information about the process: the name of the
executable, its current state, its PID and PPID, its real
and effective UID and GID, its memory usage, and other
information. Note that the stat
and
statm
files are obsolete. The information
they contained is now stored in
status
.
If we list the contents
of the fd
directory for a randomly chosen
process we obtain this:
# ls -l /proc/8141/fd/ total 4 lrwx------ 1 peter peter 64 Aug 4 09:05 0 -> /dev/tty1 lrwx------ 1 peter peter 64 Aug 4 09:05 1 -> /dev/tty1 lrwx------ 1 peter peter 64 Aug 4 09:05 2 -> /dev/tty1 l-wx------ 1 peter peter 64 Aug 4 09:05 3 -> /home/peter/seti32/lock.sah #
In fact, this is the list of file descriptors opened by the process. Each opened descriptor is shown by a symbolic link, where the name is the descriptor number, and which points to the file opened by this descriptor[7]. Note the permissions on the symlinks: this is the only place where they make sense, as they represent the permissions with which the file corresponding to the descriptor has been opened.
[7] If you remember what was
described in Section 4, “Redirections and Pipes”, you know what
descriptors 0
, 1
and
2
stand for. Descriptor 0
is
the standard input, descriptor 1
is the
standard output and descriptor 2
is the
standard error.