by BehindJava

What is the difference between a Process and a Thread and real time example.

Home » java » What is the difference between a Process and a Thread and real time example.

In this tutorial we are going to learn about the differences between Process and a Thread with a real time example.

Process:

  1. An executing instance of a program is called a process.
  2. Some operating systems use the term ‘task‘ to refer to a program that is being executed.
  3. A process is always stored in the main memory also termed as the primary memory or random access memory.
  4. herefore, a process is termed as an active entity. It disappears if the machine is rebooted. Several process may be associated with a same program.
  5. On a multiprocessor system, multiple processes can be executed in parallel.
  6. On a uni-processor system, though true parallelism is not achieved, a process scheduling algorithm is applied and the processor is scheduled to execute each process one at a time yielding an illusion of concurrency.

Example: Executing multiple instances of the ‘Calculator’ program. Each of the instances are termed as a process.

Thread:

  1. A thread is a subset of the process.
  2. It is termed as a ‘lightweight process’, since it is similar to a real process but executes within the context of a process and shares the same resources allotted to the process by the kernel.
  3. Usually, a process has only one thread of control – one set of machine instructions executing at a time.
  4. A process may also be made up of multiple threads of execution that execute instructions concurrently.
  5. Multiple threads of control can exploit the true parallelism possible on multiprocessor systems.
  6. On a uni-processor system, a thread scheduling algorithm is applied and the processor is scheduled to run each thread one at a time.
  7. All the threads running within a process share the same address space, file descriptors, stack and other process related attributes.
  8. Since the threads of a process share the same memory, synchronizing the access to the shared data within the process gains unprecedented importance.

Real world example for Process and Thread This will give you the basic idea about thread and process

tit