Process vs. Thread

24 Feb 2011 by

Process and Thread are two unit of executions that are not the same in the sense of executing environment. These two terms often are used confusingly. This article will clear all the doubts.

Process

Process is a compiled program requires CPU to execute its instructions and also requires its own memory space for storing its executing environment. If we peep into the memory of computer, Process can be divided at least into 3 segments:

  • Text segment: storing program code
  • Heap: storing global data
  • Stack: storing local data
Process segmentation in computer memory

Process Segmentation

The purpose of segmentation in memory is to distinguish between instruction and data. Let’s say 0xA2 in hexadecimal. If it is stored in Text Segment, it is MOV instruction. On the hand, if it is stored in Heap or Stack, it equals 162 in decimal.

Some main feature of Process:

  • Has its own memory space
  • Has its own unique process ID
  • Creating and destroying Process is cost heavily
  • Communication between processes is done based on Inter-Process Communication (IPC) or pipe (UNIX-like system)

Thread

Thread sometimes is called light weight process. However, it has some unique features making it differences from Process.

Some main feature of Thread:

  • Thread exists within a process
  • Every process has at least one thread called main thread
  • The main thread has an ability to create additional threads
  • Thread share process’s resources, including memory, open files, socket. This makes efficient in communication among each other but giving some sorts of potential problematic. This problem will be discussed in Mutual Exclusion.
Threads exist in a Process and share Process's resources

Process and Thread

2 responses so far

Leave a Reply