concepts

procfs — Process and Kernel Information

procfs is a virtual filesystem that exports kernel and process information; many entries are generated on access rather than stored as ordinary disk files. /proc/self refers to the accessing process, so a shell and its child may observe different PIDs. status offers named fields; stat is positional and requires careful parsing (the process name may contain spaces or parentheses). Access to other processes depends on permissions and mount policy, and a process may disappear between reads. Numeric PIDs can be reused; an existing procfs descriptor for an exited task does not become a descriptor for its replacement. Some entries, including /proc/sys, accept writes; reading them is not equivalent to changing a setting. Use selected fields instead of dumping command lines, environments or address maps from unrelated processes. The example reads its own Pid and Uid fields, validates them against Python's process identity and normalizes the output. It does not enumerate other users or change tunables. Example prerequisites: Linux, Bash and Python 3 standard library; run as a non-root user in a private temporary working directory. Example scope: native read-only observation. Expected output: procfs self PID and credentials match. No system configuration changes.

Formal Syntax & Structure

linux syntaxlinux
/proc/self/status; /proc/self/fd/; /proc/meminfo

Parameters & Attributes

NameTypeDescription
selfmagic symlinkResolves to the caller process directory.
statustext interfaceNamed process status fields.
hidepidmount optionCan restrict visibility of other processes.

Return Value

Concept / observation

Reads yield a dynamic snapshot, not a transaction; unavailable fields or permission errors need handling.

Working Example

Example Snippetlinux
python3 - <<'PY'import osfrom pathlib import Pathrows = dict(line.split(':',1) for line in Path('/proc/self/status').read_text().splitlines() if ':' in line)assert int(rows['Pid']) == os.getpid()assert list(map(int,rows['Uid'].split()))[:2] == [os.getuid(),os.geteuid()]print('procfs self PID and credentials match')PY
Linux Reference