Supplement · Core

20 câu hỏi OS process/thread và Tomcat

Trả lời theo resource ownership → scheduler/queue → failure mode → evidence → mitigation.

Process và thread

1. Process khác thread?
Process là protection/resource container với address space/FD/credentials; threads là schedulable contexts chia sẻ phần lớn process resources nhưng có registers/stack/TID riêng.
2. Thread rẻ hơn process ở đâu?
Creation/communication có thể ít isolation/copy hơn nhờ shared address space; đổi lại races/failure blast và stack/scheduling vẫn có cost.
3. Context switch cost?
Save/restore state, scheduler work và cache/TLB/locality disruption; cost phụ thuộc workload/platform, đo thay vì dùng con số cố định.
4. RSS khác heap?
RSS là resident process pages gồm heap, stacks, code, native/direct/mmap/shared; Java heap chỉ một vùng. PSS phân bổ shared pages để so processes.
5. Load average cao CPU thấp?
Có thể nhiều tasks uninterruptible I/O hoặc quota/throttle; xem run queue, iowait, task states/cgroups, không kết luận CPU-bound.
6. FD leak biểu hiện?
Open FD tăng tới RLIMIT, lỗi open/socket/accept; inspect /proc/pid/fd/lsof theo type/stack/lifecycle, không chỉ tăng ulimit.
7. SIGTERM khác SIGKILL?
TERM có thể handle để drain/cleanup; KILL kernel terminate không handler/finally. Orchestrator thường TERM rồi KILL sau grace.
8. PID 1 container caveat?
Signal forwarding/default handling và orphan reaping; exec-form entrypoint hoặc init wrapper phù hợp, test shutdown.
9. Java virtual thread là kernel thread?
Không 1:1; JVM schedule virtual threads trên carrier platform threads, nhưng native pinning/downstream resources/CPU vẫn bounded.
10. OOMKilled khác OutOfMemoryError?
cgroup/kernel có thể kill process khi memory limit, không đảm bảo JVM throw/capture heap OOME; correlate container events, memory.current/events và JVM/NMT.

Tomcat

11. Tomcat request path?
Connector/Coyote accept+parse → Engine/Host/Context Valve pipeline → Filter chain/Servlet/Spring app → response, qua executor/queues và downstream resources.
12. maxThreads tăng có tốt?
Chỉ nếu CPU/downstream/DB capacity chịu; tăng concurrency có thể tăng queue/context switch/memory và overload dependency. Dùng workload/SLO evidence.
13. acceptCount vs OS backlog?
Tomcat setting diễn đạt queue khi connector max connections reached; kernel listen/SYN/accept queues là layers riêng và platform có thể cap.
14. Tomcat classloader leak?
Parent/long-lived thread/ThreadLocal/driver/cache giữ WebappClassLoader cũ sau redeploy; heap dominator/thread lifecycle evidence, close resources hoặc restart immutable process.
15. WAR vs embedded JAR?
WAR chia sẻ external container/ops model; embedded JAR owns version/config/lifecycle và phù hợp immutable deploy. Servlet semantics vẫn còn.
16. Trust X-Forwarded-For?
Chỉ sau trusted proxy strip/overwrite và server trust-list; client tự gửi được nên trust bừa gây spoof IP/audit/rate limit.
17. TLS ở proxy hay Tomcat?
Theo trust/compliance/operations: edge termination đơn giản, re-encrypt/mTLS khi hop cần; direct Tomcat cần key/cert/SNI/rotation ownership.
18. AJP có cần không?
Chỉ khi architecture dùng; giảm attack surface bằng disable hoặc private bind/firewall/secret/current patch. HTTP proxy thường đủ.
19. Graceful shutdown kiểm gì?
Remove traffic, stop intake, drain request/async/consumer, close resources trong grace; verify long request, keep-alive và SIGTERM—not chỉ process exit.
20. p99 cao CPU thấp ở Tomcat?
Inspect connector/executor queue, active stacks, DB/HTTP pool acquire, locks, DNS/TLS/downstream/GC; find first growing wait before latency.