Who does /proc/self point to in Linux? Understanding it by comparing Bash and awk PIDs

Linux・CLI・DevOpsカテゴリを表すパンダのイラスト Linux / CLI / DevOps

About This Article
This article is created using an automated generation workflow powered by generative AI. Based on Linux kernel procfs documentation and existing executed Daily-Code-Samples, it verifies: /proc/self observes who refers to whom through safe, read-only operations.

Verification Status: 🧪 Locally verified on Debian 13 / Bash 5.2.37; Ubuntu actual hardware unverified

/proc is not a collection of ordinary disk folders, but a virtual file system where the kernel exposes processes and system states in a file-like format. First, by reading your own PID and /proc/self, you can observe a somewhat unexpected behavior.

Run First

Sensitive information such as /proc/*/environ will not be touched. We only read Name, Pid, and PPid from the status file.

echo "[SHELL] Bash PID = $$"

echo '[OBSERVE 1] /proc/$$/status'
awk '/^(Name|Pid|PPid):/ {print}' "/proc/$$/status"

echo '[OBSERVE 2] /proc/self/status'
awk '/^(Name|Pid|PPid):/ {print}' /proc/self/status

The basics of procfs can be found in the Linux kernel documentation.

View Here

In the first case, Pid matches Bash’s own $$. However, in the second case, depending on the environment, it becomes Name: awk and the PID differs from Bash.

This is because self in /proc/self refers not to “the shell that wrote the command,” but to the process that actually references that path. In this example, awk opens /proc/self/status.

flowchart LR
    B["Bash PID = $$"] --> A[Launch awk]
    A --> P["Open /proc/self/status"]
    P --> K["Kernel / procfs"]
    K --> R[Returns awk's own PID]

Change One Part

This time, instead of self, explicitly specify Bash’s PID.

cat "/proc/$$/cmdline" | tr '\0' ' '
echo

Since /proc/$$ fixes the target PID, even if another process’s cat reads it, the reference target remains Bash.

Why It Looks Like Files

procfs is an interface that exposes internal kernel information to user space. When reading status, rather than thinking of it as opening a saved text file, it is easier to understand if you view it as “the kernel presenting the current state in a file-like manner.”

Once you understand this concept, it becomes easier to trace what information Linux exposes behind ps and monitoring tools.

Safety and Precautions

  • /proc/*/environ contains environment variables and sensitive information; do not output unnecessary data to articles or logs.
  • Other users’ processes may appear differently depending on permissions and mount configurations.
  • PIDs that terminate instantly may disappear during observation.
  • Because this is a Linux-specific mechanism, do not generalize it directly to other OSs.

References and Resources

Summary: /proc/<PID> represents the specified process, while /proc/self represents the process itself referencing that path. Even through a small reading experiment, you can experience how Linux exposes kernel state as a file-like interface.

この記事の更新履歴

この記事は、生成AIを活用した自動レビュー・更新フローにより内容を見直し、必要な修正を反映しています。

2026年9月26日

  • 変更不自然に分割・破損していた見出しタグの構造を修正しました。
  • 変更リストタグ内に埋め込まれていた段落やテキストの配置を修正しました。

Document information

Article title
Who does /proc/self point to in Linux? Understanding it by comparing Bash and awk PIDs
Published
Updated
Source
https://papanda925.com/?p=17051&lang=en

License: Text and original figures for which this site holds the relevant rights are available under CC BY 4.0 , unless otherwise noted. This article may include content created or edited with generative AI. If code has a separate license notice or a linked GitHub repository license, that license takes precedence for the code. Quotations, third-party materials, images, and trademarks are excluded from this license. Usage policy

Copied title and URL