Trung BìnhOperating System iconOperating System

Linux signals là gì? Các signal quan trọng và cách handle graceful shutdown?

Signal là cơ chế notification asynchronous mà OS hoặc process khác gửi đến process: SIGTERM (15, terminate request — default cho kill PID), SIGKILL (9, force kill — không thể catch/ignore), SIGINT (2, Ctrl+C), SIGHUP (1, terminal closed/reload config), SIGUSR1/SIGUSR2 (user-defined, Node.js dùng SIGUSR1 để enable debugger), SIGCHLD (child process terminated), SIGPIPE (write to broken pipe).

Graceful shutdown là critical trong production: khi nhận SIGTERM, server stop accepting new connections, drain in-flight requests, close DB connections, flush logs — rồi mới exit. Node.js graceful shutdown: process.on('SIGTERM', async () => { await server.close(); await db.disconnect(); process.exit(0); }).

Kubernetes gửi SIGTERM trước khi terminationGracePeriodSeconds (default 30s), sau đó gửi SIGKILL — phải handle SIGTERM để zero-downtime deploy. Go: signal.NotifyContext(ctx, syscall.SIGTERM) để propagate cancellation đến tất cả goroutines khi nhận signal.

Xem toàn bộ Operating System cùng filter theo level & chủ đề con.

Mở danh sách Operating System