Monday, September 30, 2013

Differences between processes and threads in operating systems



Differences between processes and threads in operating systems

 
Process is a series of actions or steps taken to achieve an end. And the thread is a single sequence stream within in a process.

A process is a program in execution of an application, whereas a thread is a path of execution within a process. For example, when we double-click the Microsoft Word icon, we start a process that runs Word and begins executing the primary thread of that process.   

A process can contain multiple threads.  

Processes are generally used to execute large or ‘heavyweight’ tasks such as running different applications, while threads are used to carry out much smaller or ‘lightweight’ tasks such as spelling checking, auto capitalization or saving a document, etc in a program.

Threads are considered lightweight because they use far less resources than processes. 

Each process has its own address space, but the threads within the same process share that address space. Therefore, Switching between threads is much simpler and faster than switching between processes 

Processes are independent of each other. Threads, since they share the same address space are interdependent in a process.

Threads are easier to create than processes since they don't require a separate address space.
  
Threads also have a great degree of control over other threads of the same process. Processes only have control over child processes.


Any changes made to the main thread may affect the behavior of other threads within the same process. However, changes made to the parent processes do not affect the child processes.  


Similarities between process and thread

·       A thread can do anything that a process can do.

·       They both have ID- Process has a process ID same way thread has a thread ID.

·       They are both able to reproduce - Processes create child processes and threads create more threads.

·       We can create a process within a process same way we can create thread within a thread

·       Both process and thread has priorities.



To understand the differences between processes and threads, let us consider someone is making a cake which is a process. And for making a cake he or she need to collect ingredients, have to make dough, put in the oven for baking, preparing the cream for coating, decorate the cake, etc. These little tasks are actually threads of his or her process to make a cake.

Let us consider another example. Suppose someone is traveling to abroad. To go from one country to another he or she needs to process visa, collect ticket, make the luggage, arrive at airport, etc. All these small tasks are threads for making the process for traveling to abroad.

 

Consider Windows and Linux Threads

In Linux, there is no difference between processes and threads; as an alternative it simply uses the term task. On the other hand in windows there are differences between processes and threads.

There are little bit differences between threads and processes in Linux exist because the entire context of the process is not present in the main process data structure. Instead the context is contained in independent data structures. The process data structure simply holds pointers to these separate structures. But in windows, all the data vital to the process are contained exclusively within the process itself.

In Linux, the preemptive multitasking model has been designed into the kernel from day one. But In the beginning of the Windows road to Vista the operating system was a single tasking architecture. Then it started out with co-operative multitasking then moved on to a preemptive multitasking model.
In Linux, all devices are treated as files. This makes programming and access to both normal files and device files easier and standardized. The result of this is programming is simpler and simpler programs run faster and use less memory.
Windows still manages to get itself into a bind when trying to do too many things at the same time. Linux is a bit more intelligent in its allocation and the total impact on the system is less.

In Linux, the scheduler represents a higher priority of execution by a lower number, whereas in Windows it is represented by a higher number.

 

 

No comments:

Post a Comment