Process:
A process in Linux (and Android, which is Linux-based) is more than just running code — it’s a container of resources, including:
Access to kernel-managed resources like memory maps, I/O handles, sockets, etc.
Its own virtual address space
One or more threads (each with its own stack)
Open file descriptors
Environment variables
Signal handlers
A current working directory
A process ID (PID) and parent process ID (PPID)
Thread:
A lightweight unit of execution within a process. All threads of a process share memory and resources like file descriptors
| Feature | Process | Thread |
|---|---|---|
| Address Space | Separate (isolated) | Shared with other threads |
| Memory Sharing | No (by default) | Yes (heap, globals, file descriptors) |
| Crash Impact | Only that process is affected | Entire process can crash |
| Communication | Needs IPC (e.g., Binder, sockets) | Shared memory + sync (e.g., mutex) |
| Use in Android | Apps, services like system_server | UI thread, Binder thread pool |
Android Context
- Apps: Each Android app runs in its own process (started via Zygote), for security and stability.
- System Services: Many run in the SystemServer process, using multiple threads to handle tasks (e.g., Binder calls).
- UI Thread: Each app has a main thread responsible for handling UI events.
- Binder Thread Pool: Services can spawn multiple threads to handle IPC calls concurrently.
When to Use
- Use processes when you need:
- Isolation
- Crash containment
- Security separation
- Use threads when you need:
- Fast communication
- Shared access to memory
- Responsiveness (e.g., UI, background workers)
Summary
- Threads run inside a process and share memory.
- Processes are independent and provide stronger isolation.
- In Android,
apps = processes,services/components = threads. - Choosing between them depends on performance vs isolation tradeoffs.
Leave a comment