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
/proc/self/status; /proc/self/fd/; /proc/meminfoParameters & Attributes
| Name | Type | Description |
|---|---|---|
| self | magic symlink | Resolves to the caller process directory. |
| status | text interface | Named process status fields. |
| hidepid | mount option | Can restrict visibility of other processes. |
Return Value
Reads yield a dynamic snapshot, not a transaction; unavailable fields or permission errors need handling.
Working Example
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