Os Test 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

OS TEST 2

1. Different btn process and thread

Process: 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. 
The process can have the following states new, ready, running, waiting,
terminated, and suspended. 
Thread: Thread is the segment of a process which means a process can
have multiple threads and these multiple threads are contained within a
process. A thread has three states: Running, Ready, and Blocked. 
The thread takes less time to terminate as compared to the process but
unlike the process, threads do not isolate. 

Difference between Process and Thread: 


S.NO Process Thread

Process means any program is


1. in execution. Thread means a segment of a process.

The process takes more time to


2. terminate. The thread takes less time to terminate.

3. It takes more time for creation. It takes less time for creation.

It also takes more time for


4. context switching. It takes less time for context switching.

The process is less efficient in Thread is more efficient in terms of


5. terms of communication. communication.

We don’t need multi programs in action for


Multiprogramming holds the multiple threads because a single process
6.  concepts of multi-process. consists of multiple threads.
S.NO Process Thread

7. The process is isolated. Threads share memory.

The process is called the A Thread is lightweight as each thread in a


8. heavyweight process. process shares code, data, and resources.

Process switching uses an Thread switching does not require calling an


interface in an operating operating system and causes an interrupt to the
9. system. kernel.

If one process is blocked then it


will not affect the execution of If a user-level thread is blocked, then all other
10. other processes  user-level threads are blocked. 

The process has its own Thread has Parents’ PCB, its own Thread
Process Control Block, Stack, Control Block, and Stack and common Address
11. and Address Space. space.

Since all threads of the same process share


address space and other resources so any
Changes to the parent process changes to the main thread may affect the
12. do not affect child processes. behavior of the other threads of the process.

No system call is involved, it is created using


13. A system call is involved in it. APIs.

The process does not share data


14. with each other. Threads share data with each other.
What is a Thread?
A thread is a lightweight process that can be managed independently by a scheduler. It
improves the application performance using parallelism. A thread shares information
like data segment, code segment, files etc. with its peer threads while it contains its
own registers, stack, counter etc.
A thread is basically a subpart of a large process. In a process, all the threads within it
are interrelated to each other. A typical thread contains some information like data
segment, code segment, etc. This information is being shared to their peer threads
during execution.
The most important feature of threads is that they share memory, data, resources, etc.
with their peer threads within a process to which they belong. Also, all the threads
within a process are required to be synchronized to avoid unexpected results.
A thread is a single sequential flow of execution of tasks of a process so it is also known as
thread of execution or thread of control. There is a way of thread execution inside the process of
any operating system. Apart from this, there can be more than one thread inside a process. Each
thread of the same process makes use of a separate program counter and a stack of activation
records and control blocks. Thread is often referred to as a lightweight process.

A thread is a lightweight process that can be managed independently by a scheduler. It


improves the application performance using parallelism.
A thread shares information like data segment, code segment files etc. with its peer
threads while it contains its own registers, stack, counter etc.
The two main types of threads are user-level threads and kernel-level threads. A
diagram that demonstrates these is as follows 

Advantages of thread

o Enhanced throughput of the system: When the process is split into many


threads, and each thread is treated as a job, the number of jobs done in the unit
time increases. That is why the throughput of the system also increases.
o Effective Utilization of Multiprocessor system: When you have more than one
thread in one process, you can schedule more than one thread in more than one
processor.
o Faster context switch: The context switching period between threads is less than
the process context switching. The process context switch means more overhead
for the CPU.
o Responsiveness: When the process is split into several threads, and when a
thread completes its execution, that process can be responded to as soon as
possible.
o Communication: Multiple-thread communication is simple because the threads
share the same address space, while in process, we adopt just a few exclusive
communication strategies for communication between two processes.
o Resource sharing: Resources can be shared between all threads within a process,
such as code, data, and files. Note: The stack and register cannot be shared
between threads. There is a stack and register for each thread.

What is swapping? 
Swapping is moving data between physical memory(RAM) and secondary memory. In
computing, virtual memory is a management technique that combines a computer’s hard disk space
with its random access memory (RAM) to create a larger virtual address space. This can be useful if
you have too many processes running on your system and not enough physical memory to store
them.

While performing swapping the operating system needs to allocate a block of memory. It finds the
first vacant block of physical memory.

As each new block of memory is allocated, it replaces the oldest block in physical memory. When a
program attempts to access a page that has been swapped out, the operating system copies the page
from the disk into physical memory and updates the page table entry.

The purpose of operating system swapping is to increase the degree of multiprogramming and
increase main memory usage. 

 There are two steps to changing the operating system: 

 Swap-in: A swap-in process in which a process moves from secondary storage / hard disk to main
memory (RAM). 
 Swap out: Swap out takes a process out of the main memory and places it in secondary memory.
Advantages of Swapping

 Swapping can help to make more room and allow your programs to run more smoothly.
Additionally, swap files can also be helpful in cases where you have multiple programs open at the
same time. 
 Using a swap file, you can ensure that each program has its own dedicated chunk of memory,
which can help improve overall performance.
 Improve the degree of multi-programming.
 Better RAM utilization.

Disadvantages of Swapping

 If the computer system is turned off during high paging activity, the user may lose all information
related to the program. 
 The number of page faults increases, which can reduce overall processing performance. 
 When you make a lot of transactions, users lose information and computers lose power.

You might also like