Linux Operating System
Linux Operating System
Submitted by
Singh Priyanka Gopal (226580316049)
SR.NO. TOPICS
1 Threads
2 Processes
A thread is a single sequence stream within a process. Threads are also called lightweight
processes as they possess some of the properties of processes. Each thread belongs to
exactly one process. In an operating system that supports multithreading, the process
can consist of many threads. But threads can be effective only if CPU is more than 1
otherwise two threads have to context switch for that single CPU.
Why Multi-Threading?
Threads run in parallel improving the application performance. Each such thread has its
own CPU state and stack, but they share the address space of the process and the
environment.
Threads can share common data so they do not need to use interprocess
communication. Like the processes, threads also have states like ready, executing,
blocked, etc.
Priority can be assigned to the threads just like the process, and the highest priority
thread is scheduled first.
Each thread has its own Thread Control Block(TCB). Like the process, a context switch
occurs for the thread, and register contents are saved in (TCB). As threads share the same
address space and resources, synchronization is also required for the various activities of
the thread.
PROCESSES
Processes are basically the programs that are dispatched from the ready state and are
scheduled in the CPU for execution. PCB(Process Control Block) holds the concept of
process. A process can create other processes which are known as Child Processes. The
process takes more time to terminate and it is isolated means it does not share the
memory with any other process.
THREADS V/S PROCESSES
Sr. No. Threads Process
1 Thread means a segment of a Process means any program is in
process. execution.
2 The thread takes less time to The process takes more time to
terminate. terminate.
3 It takes less time for creation. It takes more time for creation.
4 It takes less time for context It also takes more time for context
switching. switching.
5 Thread is more efficient in terms of The process is less efficient in terms
communication. of communication.
6 Threads share memory. Threads share memory.
7 A Thread is lightweight as each The process is called the heavyweight
thread in a process shares code, process.
data, and resources.
8 We don’t need multi programs in Multiprogramming holds the
action for multiple threads because concepts of multi-process.
a single process consists of multiple
threads.
9 Thread switching does not require Process switching uses an interface in
calling an operating system and an operating system.
causes an interrupt to the kernel.
10 If a user-level thread is blocked, then If one process is blocked then it will
all other user-level threads are not affect the execution of other
blocked. processes.
11 Thread has Parents’ PCB, its own The process has its own Process
Thread Control Block, and Stack and Control Block, Stack, and Address
common Address space. Space.
12 No system call is involved, it is A system call is involved in it.
created using APIs.
13 Since all threads of the same process Changes to the parent process
share address space and other do not affect child processes.
resources so any changes to the main
thread may affect the behavior of the
other threads of the process.
BENEFITS OF USING THREADS
1) Responsiveness
Multi-threading allows an application to perform more than one task
simultaneously. So, when some part of an application is busy performing a lengthy
operation or waiting for an I/O, another part can continue its execution. So the
application is not getting blocked on a single operation. Thus providing
responsiveness.
2) Resource Sharing
Threads share the memory and the resources of the process to which they belong.
Due to this, different threads can work efficiently within the same single process
environment.
3) Economy
Allocating memory and resources for a process is costly. Compared to this, threads
share the resources of a process by default. Also, process creation, scheduling, and
termination are time-consuming compared to threads. Due to this, threads are called
lightweight processes.
4) Utilization of multi-processor architectures
In single-processor architecture, the CPU quickly switches among various threads
to provide an illusion of parallelism. In reality, only one thread runs at a time.In a
multi-processor architecture, each thread can run in parallel on a different processor.
Thus it provides real parallelism. This increases concurrency.
CONCLUSION
Hence, I have learnt such a wonderful topics that are Threads, Processes, Threads v/s
Processes and Benefits of using threads.
THANKYOU