惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security Affairs
N
News and Events Feed by Topic
T
Tenable Blog
P
Proofpoint News Feed
W
WeLiveSecurity
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
Help Net Security
Help Net Security
I
Intezer
T
Threat Research - Cisco Blogs
S
Secure Thoughts
C
Cyber Attacks, Cyber Crime and Cyber Security
L
Lohrmann on Cybersecurity
AWS News Blog
AWS News Blog
Google Online Security Blog
Google Online Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
The Hacker News
The Hacker News
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tor Project blog
N
News | PayPal Newsroom
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
Arctic Wolf
Forbes - Security
Forbes - Security
O
OpenAI News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Latest
Security Latest
P
Palo Alto Networks Blog
S
Schneier on Security
S
Securelist
C
Cybersecurity and Infrastructure Security Agency CISA
H
Heimdal Security Blog
V
Vulnerabilities – Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园_首页
T
Troy Hunt's Blog
Latest news
Latest news
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
人人都是产品经理
人人都是产品经理
L
LINUX DO - 热门话题
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium
V
Visual Studio Blog
H
Hacker News: Front Page

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Understanding PID Namespaces: The Small Linux Feature Behind Container Process Isolation
amir · 2026-05-19 · via DEV Community

Understanding PID Namespaces: The Small Linux Feature Behind Container Process Isolation

When people first learn containers, they usually hear this sentence:

“A container is just a process.”

That sentence is true, but incomplete.

A better version is:

“A container is a regular Linux process running with a different view of the system.”

One of the most important parts of that different view is the PID namespace.

A PID namespace controls what processes a process can see and what process IDs look like from inside that environment. It is one of the Linux kernel features that makes containers feel isolated, even though everything is still running on the same host kernel.

Docker, containerd, runc, Kubernetes, and even small learning projects like a tiny Docker-like runtime all rely on this idea.


What problem does a PID namespace solve?

On a normal Linux machine, every process has a PID:

ps aux

Enter fullscreen mode Exit fullscreen mode

You may see things like:

PID 1      systemd
PID 842    sshd
PID 1201   nginx
PID 2300   node

Enter fullscreen mode Exit fullscreen mode

Without PID isolation, a process inside a container could see host processes. That would be noisy, confusing, and dangerous.

With a PID namespace, the container gets its own process ID view.

Inside the container:

PID 1      app
PID 7      worker
PID 12     shell

Enter fullscreen mode Exit fullscreen mode

On the host, those same processes still have real host PIDs:

PID 34520  app
PID 34541  worker
PID 34610  shell

Enter fullscreen mode Exit fullscreen mode

So the same process can have two identities:

  • one PID inside the container
  • another PID on the host

This is not magic. It is namespace-based translation done by the Linux kernel.


PID 1 is not just “the first process”

A very common beginner mistake is thinking PID 1 is only a number.

It is not.

Inside a PID namespace, the first process becomes PID 1, and PID 1 has special responsibilities.

In a normal Linux system, PID 1 is usually systemd or another init system. In a container, PID 1 might be your application:

docker run my-api

Enter fullscreen mode Exit fullscreen mode

If your app becomes PID 1 directly, it now behaves like the init process of that namespace.

That matters because PID 1 is responsible for handling orphaned child processes and reaping zombies. The Linux man pages describe the first process in a new PID namespace as the namespace init process, and orphaned children in that namespace are reparented to it.

This is why senior engineers often care about tiny init processes like:

tini
dumb-init

Enter fullscreen mode Exit fullscreen mode

Without a proper init process, long-running containers can slowly accumulate zombie processes.

A container may look healthy from the outside, but inside it can be leaking process table entries because PID 1 is not doing its job.


The senior-level lesson: containers are isolation, not virtualization

A VM gets its own kernel.

A container does not.

A container shares the host kernel, but gets isolated views using kernel features like:

  • PID namespaces
  • mount namespaces
  • network namespaces
  • UTS namespaces
  • IPC namespaces
  • user namespaces
  • cgroups

The PID namespace only isolates process visibility and PID numbering. It does not magically secure everything.

That is a critical mental model.

A PID namespace can stop a container from seeing host processes, but it does not protect you from:

  • dangerous Linux capabilities
  • privileged containers
  • host filesystem mounts
  • exposed Docker socket
  • weak seccomp, AppArmor, or SELinux profiles
  • kernel vulnerabilities
  • bad Kubernetes security context settings

This is why container security is usually about layers, not one feature.


How Docker uses PID namespaces

By default, Docker gives containers their own PID namespace.

Docker exposes this through the --pid option. The default mode isolates processes, while --pid=host makes the container use the host PID namespace.

Example:

docker run --rm -it ubuntu ps aux

Enter fullscreen mode Exit fullscreen mode

Inside the container, you may see only a few processes.

But with host PID mode:

docker run --rm -it --pid=host ubuntu ps aux

Enter fullscreen mode Exit fullscreen mode

The container can see host processes.

That flag is useful for debugging, monitoring, and observability tools, but it should be treated carefully. In production, --pid=host removes an important isolation boundary.


What is the “hash” inside /proc/<pid>/ns/pid?

When you inspect namespaces, you may see something like this:

readlink /proc/$$/ns/pid

Enter fullscreen mode Exit fullscreen mode

Output:

pid:[4026531836]

Enter fullscreen mode Exit fullscreen mode

People sometimes casually call this a “namespace hash”, but it is not a cryptographic hash.

It is a kernel namespace identifier exposed through procfs. Namespace references are shown as special symbolic links, and the number helps identify whether two processes are in the same namespace.

If two processes show the same namespace ID for pid, they share the same PID namespace.

Example:

readlink /proc/1/ns/pid
readlink /proc/$$/ns/pid

Enter fullscreen mode Exit fullscreen mode

If both return the same value, both processes are in the same PID namespace.

This is very useful for debugging containers.


How to check PID namespace isolation

From inside a container:

ps aux

Enter fullscreen mode Exit fullscreen mode

If you only see the container’s own processes, PID isolation is probably enabled.

Check the namespace ID:

readlink /proc/1/ns/pid
readlink /proc/$$/ns/pid

Enter fullscreen mode Exit fullscreen mode

From the host, inspect a container process:

docker inspect --format '{{.State.Pid}}' <container_id>

Enter fullscreen mode Exit fullscreen mode

Then:

readlink /proc/<host_pid>/ns/pid

Enter fullscreen mode Exit fullscreen mode

You can compare namespace IDs between host processes and container processes.

Another useful command:

lsns -t pid

Enter fullscreen mode Exit fullscreen mode

This shows PID namespaces on the system.

For deeper debugging:

pstree -p

Enter fullscreen mode Exit fullscreen mode

or:

ps -eo pid,ppid,cmd

Enter fullscreen mode Exit fullscreen mode

The trick is to always remember that the host sees the full truth, while the container sees a translated view.


How PID namespace isolation can be weakened

This is where many real-world mistakes happen.

PID namespaces are not usually “bypassed” by magic. They are usually weakened by configuration choices.

Here are common examples.

1. Running with host PID namespace

--pid=host

Enter fullscreen mode Exit fullscreen mode

This makes the container see host processes.

Sometimes this is used by monitoring tools, but it should not be the default for normal application containers.

2. Running privileged containers

--privileged

Enter fullscreen mode Exit fullscreen mode

A privileged container receives broad access that removes many normal container restrictions.

This is sometimes convenient during development, but it should be avoided for normal production workloads.

3. Mounting sensitive host paths

Examples:

-v /proc:/host/proc
-v /:/host
-v /var/run/docker.sock:/var/run/docker.sock

Enter fullscreen mode Exit fullscreen mode

Mounting the Docker socket is especially dangerous because it can effectively give control over the Docker daemon.

4. Adding dangerous capabilities

Capabilities such as these should be reviewed carefully:

SYS_ADMIN
SYS_PTRACE
NET_ADMIN
DAC_READ_SEARCH

Enter fullscreen mode Exit fullscreen mode

For PID and process security, SYS_PTRACE is especially sensitive because it relates to inspecting and tracing processes.

5. Weak Kubernetes security context

In Kubernetes, settings like these are important:

hostPID: true
privileged: true
allowPrivilegeEscalation: true

Enter fullscreen mode Exit fullscreen mode

For normal workloads, these should usually be avoided.


Defensive checklist for real projects

When reviewing a containerized service, I usually ask these questions.

Runtime

docker inspect <container_id> | grep -i pid

Enter fullscreen mode Exit fullscreen mode

Check whether the container is using host PID mode.

Capabilities

docker inspect <container_id> | grep -i cap

Enter fullscreen mode Exit fullscreen mode

Prefer dropping unnecessary capabilities:

--cap-drop=ALL

Enter fullscreen mode Exit fullscreen mode

Then add back only what is truly required.

Privileged mode

docker inspect <container_id> | grep -i privileged

Enter fullscreen mode Exit fullscreen mode

For most application containers, this should be false.

Process tree

docker exec -it <container_id> ps aux

Enter fullscreen mode Exit fullscreen mode

Look for zombie processes:

ps aux | grep Z

Enter fullscreen mode Exit fullscreen mode

If you see zombies, check whether PID 1 is properly reaping children.

Namespace comparison

readlink /proc/1/ns/pid
readlink /proc/$$/ns/pid

Enter fullscreen mode Exit fullscreen mode

Compare host and container namespace IDs.

Kubernetes

Check pod specs for:

hostPID: true
securityContext:
  privileged: true
  allowPrivilegeEscalation: true

Enter fullscreen mode Exit fullscreen mode

These settings should be intentional, documented, and reviewed.


A practical example from building a tiny container runtime

When building a minimal Docker-like runtime, PID namespace support usually starts with something like:

SysProcAttr: &syscall.SysProcAttr{
    Cloneflags: syscall.CLONE_NEWPID,
}

Enter fullscreen mode Exit fullscreen mode

But there is a subtle detail.

When you create a new PID namespace, the child process becomes PID 1 inside that namespace. The parent still lives in the old namespace.

That means your runtime has to think carefully about:

  • who becomes PID 1
  • whether PID 1 launches the user command directly
  • whether you need a small init process
  • how signals are forwarded
  • how child processes are reaped
  • what happens when PID 1 exits

This is where the learning becomes real.

Creating a namespace is easy.

Managing a namespace correctly is the hard part.


Senior engineering lessons

1. Do not confuse isolation with security

PID namespaces provide process isolation, but they are only one part of the security model.

2. PID 1 behavior matters

If your application runs as PID 1, signal handling and zombie reaping become your problem.

3. Debugging containers requires two views

Always check both:

  • inside the container
  • from the host

The same process has different PIDs depending on where you look from.

4. Most “container escapes” start with bad configuration

In real systems, the issue is often not the PID namespace itself. The issue is combining weak settings:

  • privileged mode
  • host PID
  • host mounts
  • excessive capabilities
  • exposed Docker socket

5. Use namespaces intentionally

For observability tools, hostPID or --pid=host may be required.

For normal application workloads, it is usually unnecessary risk.


References

  • Linux man-pages: PID namespaces
  • Linux Kernel Documentation: Namespaces
  • Docker documentation: docker run --pid
  • OWASP Docker Security Cheat Sheet

Final thought

PID namespaces are one of those Linux features that look simple at first:

“The container gets its own process IDs.”

But after working with real systems, you realize the deeper lesson:

Process isolation is not only about hiding PIDs. It is about controlling visibility, lifecycle, signals, debugging, and failure boundaries.

That is why PID namespaces are not just a container feature.

They are a production engineering concept.

If you understand PID namespaces well, Docker feels less like magic and more like a thin layer over powerful Linux primitives.