0% found this document useful (0 votes)
17 views29 pages

Process

The document provides lecture notes on Operating Systems for B.Tech II Year students, covering key concepts such as processes, their states, and differences between processes and programs. It details the various states of a process, including New, Ready, Running, Waiting, Suspended, and Terminated, along with examples from applications like Microsoft Word and Visual Studio Code. Additionally, it discusses the resource requirements and lifecycle of processes and programs, emphasizing their interrelated nature in computing.

Uploaded by

q8xc5r7vgg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views29 pages

Process

The document provides lecture notes on Operating Systems for B.Tech II Year students, covering key concepts such as processes, their states, and differences between processes and programs. It details the various states of a process, including New, Ready, Running, Waiting, Suspended, and Terminated, along with examples from applications like Microsoft Word and Visual Studio Code. Additionally, it discusses the resource requirements and lifecycle of processes and programs, emphasizing their interrelated nature in computing.

Uploaded by

q8xc5r7vgg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OPERATING SYSTEMS

[R18A0504]
LECTURE NOTES
[Link] II YEAR – I SEM (R18)
(2019-2020)
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
MALLA REDDY COLLEGE OF ENGINEERING &
TECHNOLOGY
(Autonomous Institution – UGC, Govt. of India)
Recognized under 2(f) and 12 (B) of UGC ACT 1956
(Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC – ‘A’ Grade - ISO
9001:2015 Certified)Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100,
Telangana State, India
MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY
II Year B. Tech CSE ‐ I Sem L T/P/D C3 -/-/- 3

(R18A0504) OPERATING SYSTEMS


OBJECTIVES:

he mechanisms of OS to handle processes and threads and their communication


To learn the mechanisms involved in memory management in contemporary OS

on algorithms, deadlock detection algorithms and agreement protocol

UNIT-I
Processes: Definition, Process Relationship, Different states of a Process, Process State
Transitions, Process Control Block (PCB), Context switching
Definition;
A process is a program in execution. When a process is
loaded into the memory and its being executed, it’s called a program.
A program on the other hand is a program is a set of instructions that a
computer can execute to perform a task, a static entity that's stored on
a disk and written in a high-level programming language. When
compiled, a program becomes an executable file with extensions like
.exe, .out, or .app.
Now that we have defined both program and process let's delve deeper
into the key difference between process and program:

Differences between Process and Program


1) A process is dynamic entity;
This means that, a process is not static. By this, we are referring to
the fact that, is continually changing in terms of its state; and by its
state, we mean a process can transition through various states such
as, new state, Running state, Waiting and Terminated state.
This state changes occur due to various events like CPU
scheduling, input and output operations, or user interactions. It
continually changes.
Meanwhile, when we refer to a program as static
object, we are highlighting its fixed nature during execution. This
means that, certain aspects of the program do not change
dynamically. This gives the program a predictable behaviour. This
means that, because the static structure and memory allocation are
fixed, its behaviour can be predicted ore easily. This predictability
can be beneficial for debugging and optimisation.
For example; let’s look at a static nature of a programme using HTML
and CSS
<! DOCTYPE HMLS
<Html>
<Head>
<Title>static page </title>
</head>
<Body>
<h1> welcome to my static Page</h1>
<p> The Cordiant class not change dynamically. <P>
</body>
</html>

The static nature of the Programme. The Content on the the Html
page the heading and Paragraph) is hard Coded in the. It doesn't
change unless you manually edit the HTML file and reload the page
- This means that, every time a user visits the page they see the
same Content.

No dynamic behaviour unlike dynamic web pages litre those wing


JavaScript or server side Scripts, this static page does not respond
to user interactions or change based on input for example, if you
wanted the Page to display different Content based on user, (like a
form Submission you would like need to implement make it
dynamic additional Programming, which can make it dynamic. In
Conclusion to this static HTML Page, this means that
2. Nature and Design
The first key difference between a process and a program is that a
program is a set of instructions designed to complete a specific task.
It is a passive entity that resides in secondary memory. On the other
hand, a process is an instance of an executing program. It is an
active entity created during execution and loaded into the main
memory.

3. Existence and Lifetime


Another key difference between program and process is that a
program exists in a single place and continues to exist until it is
deleted. It is a static entity that does not change itself. In contrast, a
process exists for a limited period. It is created during execution,
executes its tasks, and gets terminated upon completion.
4. Resource Requirements
A program has no resource requirement other than memory space
for storing its instructions. It does not require CPU time or other
resources during its execution. On the other hand, a process has a
high resource requirement. It needs CPU, memory address, and I/O
for its execution.

5. Control Blocks
A program does not have any control block associated with it. It
only consists of code and data. In contrast, a process has its own
control block called a Process Control Block (PCB). The PCB
contains information required for the management and execution
of the process.

6. Instruction Execution
A program contains a set of instructions designed to complete a
specific task. It does not execute these instructions. On the other
hand, a process is a sequence of instruction execution. It executes
the instructions present in the program code.

7. Data Manipulation
A program consists of instructions and data. It does not manipulate
data during its execution. Conversely, a process contains program
data and requires additional information for its management and
execution.

8. Multiple Processes
Program vs. Process in OS- Multiple processes can execute a single
program. The program code may be the same in such cases, but the
program data may differ between processes. This allows for
concurrent execution and efficient utilization of system resources.

After understanding the difference between program and process


in os, let’s dig into the similarities. There are several similarities
between processes and programs.
Here are some of the key similarities:

 Execution Flow:
Both processes and programs involve the execution of
instructions or code, either by the CPU for processes or by
compilation/interpretation for programs.
 Resource Usage:
Both processes and programs require system resources, such
as memory, CPU time, and input/output devices, to function
effectively.
 Code Composition: Both processes and programs are
composed of a sequence of instructions, whether the lines of
code in a program or the set of instructions being executed by
a process.
 Interactivity: Both processes and programs can interact with
users or other programs, whether it's a program taking user
input or communicating with other processes through inter-
process communication mechanisms.
 Creation and Termination: Both processes and programs
are created and eventually terminated. Programs are written
and compiled or interpreted to create processes when
executed. Processes are created and terminated by the
operating system.
 Resource Management:
Both processes and programs are managed by the operating
system. The operating system allocates resources, schedules
execution, and handles context switching for both.
 Concurrency:
Both processes and programs can be concurrent, running
simultaneously or overlapping in time, allowing for
multitasking and efficient resource utilization.
 Hierarchy:
Both processes and programs can be organized in hierarchical
structures. Programs can consist of multiple modules or
components, and processes can spawn child processes.
 Versioning and Updates:
Both processes and programs can undergo version updates
and improvements over time, leading to changes in their
behaviour or functionality.
 Lifecycle:
Both processes and programs have lifecycles. Programs go
through development, testing, deployment, and maintenance
phases. Processes transition through states like new, ready,
running, waiting, and terminated.
 Resource Isolation:
Both processes and programs operate in isolated
environments. Processes have memory space, and programs
encapsulate their logic, reducing interference between
processes or programs.
 Persistence:
Both processes and programs can persist beyond their initial
execution. Programs can be saved to storage media and
executed multiple times. Processes can run for extended
periods or be paused and resumed.
 While processes and programs have distinct roles and
characteristics, their underlying nature of executing code,
utilizing resources, and interacting with the system makes
them closely interconnected in computing.
exit
New Terminated
state
interupted
Admitted

Ready Running
state

I/O or event completion


Waiting

I/O or event wait.


Here are the different states of a process in an operating system, along with
brief explanations for each:

1. New State
- The initial state of a process when it is created. The operating system allocates resources and
prepares to load the process into memory.

2. Ready State
- The process is prepared to run and waiting for CPU time. It is in the ready queue, ready to execute as
soon as the scheduler allocates CPU resources.

3. Running State
- The process is currently being executed by the CPU. It actively uses CPU resources to execute its
instructions.

4. Waiting (or Blocked) State


- The process cannot continue executing because it is waiting for a resource, such as I/O operations or
user input. It will remain in this state until the resource becomes available.

5. Suspended State
- The process is temporarily paused and not using CPU resources. It retains its state in memory and
can be resumed later.

6. Terminated State
- The process has completed execution or has been forcibly terminated. The operating system cleans
up resources allocated to the process.
1. A process can move from the running state to the waiting state if it
needs to wait for a resource to become available.
- This means that if a running process requires a resource (e.g., a file,
a database connection, etc.) that is not currently available, it will
transition from the running state to the waiting state while it waits for
that resource to become available.

2. A process can move from the waiting state to the ready state when
the resource it was waiting for becomes available.
- Once the resource a process was waiting for becomes available, the
process can transition from the waiting state to the ready state, where
it is prepared to execute again.

3. A process can move from the ready state to the running state when it
is selected by the operating system for execution.
- The operating system's scheduler determines which process in the
ready state will be selected to move to the running state and utilize the
CPU.

4. The scheduling algorithm used by the operating system determines


which process is selected to execute from the ready state.
- The operating system uses a scheduling algorithm (e.g., FIFO, Round
Robin) to decide which process in the ready state will be chosen to run
next.

5. The operating system may also move a process from the running
state to the ready state to allow other processes to execute.
- To ensure fair resource allocation, the operating system may pre-
empt a running process and move it back to the ready state, so that
other processes can also have a chance to run.
6. A process can move from the running state to the terminated state
when it completes its execution.
- Once a process has finished its tasks and completed its execution, it
will transition from the running state to the terminated state, where the
operating system can clean up the resources used by the process.

7. A process can move from the waiting state directly to the terminated
state if it is aborted or killed by the operating system or another
process.
- If a process in the waiting state is forcibly terminated, either by the
operating system or another process, it will skip the running and ready
states and move directly to the terminated state.

8. A process can go through ready, running, and waiting states any


number of times during its lifetime.
- Processes can transition between the various states multiple times
as they execute, wait for resources, and are scheduled by the operating
system.
Examples related to process state using Microsoft word

1. New State:
- Example in Microsoft Word: When you open Microsoft Word, it enters the new state as the system
loads the application and prepares the environment.

2. Ready State:
- Example in Microsoft Word: After launching, you see the blank document page. Microsoft Word
is now in the Ready state, waiting for your input.

3. Running State:
- Example in Microsoft Word: As you start typing your document, Microsoft Word transitions to the
Running state, actively processing your keystrokes and updating the content.

4. Blocked (or Waiting) State:


- Example in Microsoft Word: If you try to insert a large image into your document, Word may
enter the Blocked state while it waits for the image to load from your hard drive.

5. Suspended (or Suspended Blocked) State:


- Example in Microsoft Word: If you minimize the Word application to work on something else,
your document goes into the Suspended state. The application is still in memory but not actively using
CPU resources.

6. Terminated (or Completed) State:


- Example in Microsoft Word: When you finish your work, save the document, and then close
Microsoft Word, the application enters the Terminated state, where it cleans up resources and exits.

The Suspended state is an important one, as it allows the operating system to temporarily pause a
process while the user switches to another task, without losing the state of the application. This helps
maintain responsiveness and efficient resource utilization.

In the context of Microsoft Word, you may encounter the Suspended state when you minimize the
application to work on something else, and then later resume your document editing session.
Process States with Visual
Studio Code
1. New State:
- Example: When you launch Visual Studio Code to start a new project, the application enters the
*new state*. This is where the system loads the necessary files and prepares the environment for
coding.

- Vivid Scenario: You decide to create a new HTML project. You open Visual Studio Code, and it
initializes, preparing everything needed for you to start coding.

2. Ready State:
- Example: After launching, you see the welcome screen and a blank workspace. At this stage,
Visual Studio Code is in the *ready state*. It’s prepared to receive your input, but no code is being
executed yet.

- Vivid Scenario: You create a new HTML file, and Visual Studio Code is ready for you to type,
but you haven’t started coding yet.

3. Running State:

- Example: Once you begin writing your HTML and CSS code, Visual Studio Code transitions
into the *running state*. It actively processes your inputs and may even run tasks like linking or
compiling in the background.

- Vivid Scenario: You write <h1>Hello, World! </h1>, and as you type, Visual Studio Code
highlights any syntax errors and provides real-time feedback.

4. Blocked (or Waiting) State:


- Example:If your code requires data from an external API and you run a fetch request, your script
may enter the *blocked state* while waiting for a response from the API.

- Vivid Scenario: You execute a function to retrieve user data, but the request is taking longer
than expected, so your process is paused until the data is received.
5. Terminated (or Completed) State:
- Example: After completing your coding project, you save your work and close Visual Studio
Code. The application then enters the *terminated state*, where it cleans up all resources.
- Vivid Scenario: You save your HTML and CSS files, then exit Visual Studio Code, and the
software shuts down, finalizing your session.

- Vivid Scenario: You minimize VS Code to check your messages but plan to return to coding
soon.

7. I/O Bound Processes:


- Example: When you open a large project that requires loading multiple files from disk, Visual
Studio Code may spend time waiting for those files to load. This is an *I/O bound process*.

- Vivid Scenario: You open a project folder, and VS Code shows a loading spinner while it
retrieves all the necessary files.

8. CPU Bound Processes:


- Example: If you run a complex build process or a script that performs heavy computations, it is
likely *CPU bound*. The process will primarily utilize the CPU for execution rather than waiting for
I/O.

- Vivid Scenario: You compile a large JavaScript application, and the CPU is fully engaged in
processing the build.

Summary of State Transitions in Visual Studio Code Context

- *New State:* Launching Visual Studio Code prepares it for use


- *Ready State:* The application shows a blank workspace, ready for
input.
- *Running State:* Actively coding and receiving real-time feedback.
- *Blocked State:* Waiting for an API response or data.
- *Terminated State:* Closing the application after saving work.
- *Suspended State:* Minimizing the application while taking a break.
- *I/O Bound vs. CPU Bound:* Depending on whether loading files or
running complex builds.

You might also like