Archive for the tag 'proc'

SBDavid

The /proc filesystem /proc/uptime

The /proc filesystem /proc/uptime

This file contains the length of time since the system was booted, as well as the amount of time since then that the system has been idle. Both are given as floating-point values, in seconds.

Example output:

[fedora@fedora ~]$ cat /proc/uptime
3677.44 1898.50

[fedora@fedora ~]$ uptime
22:58:03 up 1:01, 2 users, load average: 0.24, 0.29, 0.32
[fedora@fedora ~]$
[root@fedora ~]#

SBDavid

Directories in /proc

Directories in /proc

Every /proc directory contains quite a few directories named with a number. A listing of them starts off like this

These directories are called process directories, as they refer to a process’s ID and contain information specific to that process. The owner and group of each process directory is set to the user running the process. When the process is terminated, its /proc process directory vanishes. However, while the process is running, a great deal of information specific to that process is contained in the process directory’s various files.

# ls -l /proc
total 0
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 1
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 10
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 1066
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 11
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 12
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 13
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 14
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 15
dr-xr-xr-x 7 root root 0 2010-07-02 21:37 16

Common groups of information concerning the kernel is grouped into directories and sub-directories within /proc.

Each of the process directories contains the following files:

cmdline — Contains the command line arguments that started the process.
cwd — A link to the current working directory for the process.
cpu — Provides specific information about the utilization of each of the system’s CPUs.
environ — Gives a list of the environment variables for the process.
exe — A link to the executable of this process.
fd — A directory containing all of the file descriptors for a particular process.
maps — Contains memory maps to the various executables and library files associated with this process.
mem — The memory held by the process.
root — A link to the root directory of the process.
stat — A status of the process.
statm — A status of the memory in use by the process.
status — Provides the status of the process in a form that is much more readable than stat or statm.

Mounting confusion /proc comes to the rescue

If you are losing track of what’s mounted, and in what state? No problem, here comes /proc to the rescue:

cat /proc/mounts

This displays all mounted filesystems, the filesystem types, read/write status, and other attributes. How many hard drives are on the system? One of these will tell you and also, SCSI drives are sd, IDE are hd.

fdisk -l

or

dmesg | grep hd

or

dmesg | grep sd
SBDavid

proc pseudo-filesystem in Linux

proc pseudo-filesystem in Linux

proc-pseudo-filesystem in Linux The Linux process pseudo-filesystem, the /proc directory. Every process on the system has a directory here with its name on it, inside of which lies many things — including an fd (”file descriptor”) subdirectory containing links to all files that the process has open. Even if a file has been removed from the filesystem, a copy of the data will be righ there:

/proc/process id/fd/file descriptor

To know where to go, you need to get the id of the process that has the file open, and the file descriptor. These you get with lsof, whose name means “list open files.” (It actually does a whole lot more than this and is so useful that almost every system has it installed. If yours isn’t one of them, you can grab the latest version straight from its author.)

lsof - list open files