Process là đơn vị thực thi độc lập với không gian bộ nhớ riêng (virtual address space, heap, stack, file descriptors). Thread là đơn vị thực thi nhẹ hơn bên trong process: các thread cùng process chia sẻ heap/code/file descriptors nhưng có stack riêng. Tạo process tốn kém hơn thread (fork copy page tables), giao tiếp giữa process phức tạp hơn (IPC), nhưng cô lập tốt hơn — crash một process không ảnh hưởng process khác.
Multi-process phù hợp: Chrome (mỗi tab là process riêng để cô lập crash/security), Node.js cluster module để tận dụng CPU cores. Multi-thread phù hợp: ứng dụng cần chia sẻ dữ liệu nhiều và frequent (Java web server, game engine). Với Python, GIL (Global Interpreter Lock) ngăn true parallelism trong threads — phải dùng multiprocessing. Go goroutines là green threads cực nhẹ (~2KB stack), runtime scheduler map M goroutines lên N OS threads.
A process is an independent unit of execution with its own memory space (virtual address space, heap, stack, file descriptors). A thread is a lighter-weight unit of execution within a process: threads in the same process share the heap, code, and file descriptors but each has its own stack. Creating a process is more expensive than creating a thread (fork copies page tables), and inter-process communication is more complex (IPC), but processes provide better isolation — a crash in one process does not affect others.
Multi-process is appropriate for: Chrome (each tab is a separate process for crash/security isolation), Node.js cluster module to leverage multiple CPU cores. Multi-thread is appropriate for: applications with frequent shared data access (Java web servers, game engines). In Python, the GIL (Global Interpreter Lock) prevents true thread parallelism — multiprocessing is required for CPU-bound work. Go goroutines are extremely lightweight green threads (~2KB stack); the Go runtime scheduler maps M goroutines onto N OS threads.