Process Vs Thread

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

FeatureProcessThread
Address SpaceSeparate (isolated)Shared with other threads
Memory SharingNo (by default)Yes (heap, globals, file descriptors)
Crash ImpactOnly that process is affectedEntire process can crash
CommunicationNeeds IPC (e.g., Binder, sockets)Shared memory + sync (e.g., mutex)
Use in AndroidApps, services like system_serverUI 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

It’s Jdecoder

I am trying to decode the concepts into simple words and documenting items i know or currently learning.

Let’s connect

Design a site like this with WordPress.com
Get started