Skip to content
All writing Part 01 of 11 · 從 19 個 goroutine 到 exit 137
Engineering · 1 min read

OS 基礎詞彙:process、thread、kernel、syscall

隔離來自 process 邊界,便宜的並發來自 thread。四個 OS 詞彙,解釋為什麼兩個 process 沒有自動的backpressure。

隔離來自 process 邊界;便宜的並發來自 thread(和 goroutine)。

四個詞,一張圖

User-space Process A T1 T2 T3 threads share mem Process B T1 own memory A dies → B unaware syscall = only legal door Kernel-space memory, scheduler, NIC, disk
  • Process = 一個跑起來的程式,擁有自己的記憶體和檔案。Process A 死了,Process B 不受影響。這是為什麼截圖服務和瀏覽器 sidecar 各自有獨立的 OOM 命運(影響範圍)。
  • Thread = process 裡的一條執行線,共享同一塊記憶體。便宜的並發從這裡開始;goroutine 更便宜,~2KB 對 ~1MB(GMP 排程器)。
  • Kernel vs user-space:kernel 有完整硬體存取權;你的程式跑在 user-space 沙盒裡,只能透過 syscall 請 kernel 代勞。
  • Syscallreadepoll_wait⋯)= 跨越這道牆的唯一合法門。不是免費的,每次要 mode switch,所以才有 epoll:一次等上千個 socket(GMP 排程器)。

在這個 OOM 裡的角色

截圖服務(Go app)和瀏覽器是兩個 process。各自的記憶體、各自的 OOM。Go 的 GOMEMLIMIT 管得了自己的 heap,管不了另一個 process 的記憶體(錯誤的修法)。

兩個 process 之間沒有自動的backpressure。一個要爆了,另一個不會自己停下來。

參考來源:

Related: 參見執行環境GMP 排程器與 netpoller,或回到系列總覽

Tags #go #concurrency #reliability
// connect

Be brave | Be wise | Be grateful

21 BreakinCode

// elsewhere
LinkedInMedium (lang: en)Youtube
wh:~$William Hung· © 2026 Taipei · GMT+8 · Available for collaboration