0% found this document useful (0 votes)
25 views5 pages

Midterm Lessons

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

Midterm Lessons

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

Operating Systems Processes

Process

A Process is:

 An instance of a program in execution


 An asynchronous activity
 The “animated spirit” of a procedure
 The “locus of control” of a procedure in
execution
 The “dispatch able” unit
 A unit of work individually schedulable by an
operating system.

Formally, we define a process is an executing program,


including the current values of the program counter,
registers, and variables. The subtle difference between
a process and a program is that the program is a group
of instructions whereas the process is the activity.

A program is passive; a process is active.

Process Management Functions

1. Process creation
2. Termination of the process
3. Controlling the progress of the process
4. Process Scheduling
5. Dispatching
6. Interrupt handling/Exceptional handling
7. Switching between the processes
8. Process synchronization
9. Inter process communication support
10. Management of Process Control Blocks

Process States

The Running state

 The process that is executing on the CPU is in


the running state

The Blocked state

 A process that is waiting for something (e.g.


I/O) to complete is in the blocked state

The Ready state

 A process that is ready to be executed, but not


currently assigned to a CPU, is in the ready
state

Only one process can be running on any processor at


any instant.

Many process may be ready and waiting.


First Come First Serve Scheduling Comparison with Other Scheduling Algorithms

Overview of FCFS Scheduling FCFS vs. SJF

1. Simple and Fair - FCFS favors fairness, while Shortest Job


- FCFS follows a non-preemptive approach First (SJF) aims for optimal execution
where processes are executed in the times.
order they arrive.
FCFS vs. Priority
2. First-Come, First-Served
- It offers predictability by allowing each - FCFS treats all processes equally, while
process to run to completion before the Priority Scheduling is based on predefined
next one starts. priorities.
3. Sequential Execution
- The first process to arrive receives FCFS vs. Round Robin
immediate CPU access, followed by the
- FCFS has no time slice limitation, unlike
next in line.
Round Robin, which allocates CPU time in
Advantages of FCFS Scheduling Algorithm fixed time intervals.

1. Simplicity How to Implement FCFS Scheduling Algorithm in


- FCFS is straightforward to understand and Programming
implement, making it a suitable choice for
non-complex systems.
2. Equal Access
- Every process is given a fair chance to
execute, ensuring no priority-related bias.
3. Minimal Overhead
- The absence of context switching reduces
the overhead, enhancing efficiency.

Limitations of FCFS Scheduling Algorithm FCFS Example:

1. Convoy Effect
- If a long process arrives first, it may cause
shorter processes to wait, leading to poor
overall system performance.
2. Waiting Time
- FCFS scheduling may result in high waiting
times for processes that arrive later.
3. No Prioritization
- It doesn't consider the priority or
characteristics of processes, potentially
Turn Around Time = Completion time – Arrival Time
impacting critical tasks.
Waiting Time = Turn Around Time – Burst Time
Real-Life Examples of FCFS Scheduling
Average Turn Around Time
1. Restaurant Queues
- Customers are served in the order they Average Waiting Time
arrive, ensuring a fair allocation of
resources.
2. Ticket Counters Conclusion and Summary of FCFS Scheduling Algorithm
- First customers in line are served first,
reducing conflicts and promoting FCFS offers simplicity, fairness, and minimal overhead.
orderliness. However, it can suffer from the convoy effect, high waiting
3. Retail Checkout times, and the lack of prioritization. Understanding the
- Follows FCFS to ensure fairness in serving algorithm's advantages, limitations, and real-life examples is
customers in the order they arrive with crucial when considering its implementation.
their purchases.
Shortest Job First program then sorts the processes based on burst time and
executes them in order.
What is SJF?
Coding
SJF is a non-preemptive or preemptive scheduling algorithm
that processes the shortest job first, then the next shortest, The implementation of SJF in code depends on the
and so on. It minimizes waiting time and provides faster programming language used. Most languages provide
response times. functions to sort arrays that can be used to implement SJF.

How does it work? Examples of SJF Scheduling

The waiting time of the process is determined before 1. Batch Processing


execution. The job with the shortest execution time is given - SJF is commonly used in batch processing,
the highest priority and executed first. where similar jobs are processed together.
In this case, SJF can lead to optimal use of
When is it used?
resources and faster processing times.
SJF is commonly used in scenarios where process burst time 2. Data Entry
is known in advance, such as in batch processing. - SJF can also be used in data entry jobs,
where the amount of input data is known
Non-preemptive beforehand and can be scheduled based
on their burst time.
- In non-preemptive SJF, the running
3. Interactive Systems
process cannot be preempted until it
- Interactive systems can also benefit from
finishes executing. This means that a
SJF, as it provides quicker response times
longer job may be executing even if
and minimizes waiting time for users.
shorter jobs arrive in the queue.
- is employed when a process terminates or Comparison with Other Scheduling Algorithms
transitions from running to waiting state.
SJF
Preemptive
• Minimizes waiting and response time
- the running process can be interrupted and
preempted by a shorter job that arrives in the • Optimal for batch processing
queue. This ensures that the shortest jobs are
• May cause starvation for long processes
always executing, even if they arrive after longer
jobs. Round Robin
- is when a process transitions from a running state
• Allocates equal time slices to each process
to a ready state or from a waiting state to a ready
state • Maximizes CPU utilization
Pros and Cons of SJF • May cause high overhead

Priority Scheduling

• Assigns priority to each process

• Minimizes waiting time for high-priority processes

• May cause low-priority processes to starve

Real-World Application of SJF


Implementation of SJF 1. Google Search
Algorithm - The search engine uses SJF algorithm to
provide faster responses and optimize
The algorithm involves maintaining a ready queue of search times. Websites with the shortest
processes while calculating their burst time. Processes are response time are given priority and
then sorted based on burst time and executed in the order displayed first.
of their arrival. 2. CMS
- Content Management Systems (CMS) use
Flowchart
SJF to process user requests and optimize
The process flow starts with inputting the number of response time. User requests are sorted
processes, followed by their arrival time and burst time. The based on burst time and processed
accordingly.
3. Video Encoding Understanding SJF and its pros and cons will help you
- SJF is used in video encoding to process make informed decisions when selecting a scheduling
shorter videos first, leading to faster algorithm. Its real-world applications are diverse and
processing times and higher throughput.
range from search engines to video encoding.
SJF Non-preemptive Example represented in milliseconds
Final Thoughts
the same time:
SJF is an important algorithm that optimizes process
scheduling. However, its limitations must be taken into
account when considering its real-world applications.

SJF Non-preemptive Example represented in milliseconds


different time:

SJF non-preemptive Example represented in milliseconds:

Formula: waiting time = visiting time – arrival time

SJF Preemptive Example represented in milliseconds:

SJF Preemptive Example represented in milliseconds:

Formula: waiting time = total waiting time – no. of


millisecond process executed – time arrival

Conclusion:

Summary

SJF is a scheduling algorithm that processes the


shortest job first, leading to faster processing times
and lower waiting times. Its implementation and
performance depend on the actual process burst time,
making it difficult to use in practice.

Takeaways
Processes QA: 9. The degree of multi-programming is:
a) No. of processes executed per unit
1. Process is
time
a) Program in high level language kept
b) No. of processes in the ready queue
on desk
c) No. of processes in the I/O queue
b) Contents of main memory
d) No. of processes in the memory
c) A program in execution
10. The child process completes execution, but
d) Job in secondary memory
the parent keeps executing, then the child
2. Which of the following is not the state of a
process is known as:
process?
a) Orphan
a) New
b) Zombie
b) Old
c) Body
c) Waiting
d) Dead
d) Running
11. Context switch is involved in
3. What is the ready state of a process?
a) Switching computer on
a) When process is scheduled to run
b) Switching CPU from one process to
after some execution
another
b) When process is unable to run until
c) Switching a process on
some task has been completed
d) None of these
c) When process is using the CPU
12. Scheduling a process from Ready Queue to
d) None of the mentioned
CPU is done by
4. What is interprocess communication?
a) Short term scheduler
a) CPU registers
b) Middle term scheduler
b) Program counter
c) Long-term scheduler
c) Process stack
d) dispatcher
d) Pipe
5. The address of the next instruction to be
executed by the current process is provided by
the
a) CPU registers
b) Program counter
c) Process stack
d) pipe
6. In unix, which system call creates the new
process?
a) Fork
b) Create
c) New
d) None of the mentioned
7. A process Control Block (PCB) does not
contain which of the following:
a) Code
b) Stack
c) Program Counter
d) Bootstrap program
8. The process control block is:
a) Process type variable
b) Data structure
c) A secondary storage section
d) A block in memory

You might also like