You are on page 1of 40

SYSTEM CALLS

A system call is a mechanism that provides the interface between a


process and the operating system. It is a programmatic method in which a
computer program requests a service from the kernel of the OS.

Nahida Nazir 08/01/2021


NEED OF SYSTEM CALL
• Reading and writing from files demand system calls.
• If a file system wants to create or delete files, system calls are required.
• System calls are used for the creation and management of new processes.
• Network connections need system calls for sending and receiving packets.
• Access to hardware devices like scanner, printer, need a system call.

Nahida Nazir 08/01/2021


TYPES OF SYSTEM CALL

• Process Control
• File Management
• Device Management
• Information Maintenance
• Communications

Nahida Nazir 08/01/2021


IMPORTANT SYSTEM CALLS USED IN OS

• wait()
• In some systems, a process needs to wait for another process to complete its
execution. This type of situation occurs when a parent process creates a child
process, and the execution of the parent process remains suspended until its child
process executes
• fork()
• Processes use this system call to create processes that are a copy of themselves. With
the help of this system Call parent process creates a child process, and the execution
of the parent process will be suspended till the child process executes.

Nahida Nazir 08/01/2021


IMPORTANT SYSTEM CALLS

• exec()
• This system call runs when an executable file in the context of an already running process
that replaces the older executable file. However, the original process identifier remains as a
new process is not built, but stack, data, head, data, etc. are replaced by the new process.
• kill():
• The kill() system call is used by OS to send a termination signal to a process that urges the
process to exit. However, a kill system call does not necessarily mean killing the process and
can have various meanings.

Nahida Nazir 08/01/2021


PROCESS

A process is basically a program in execution. The execution of a process


must progress in a sequential fashion
OS helps you to create, schedule, and terminates the processes which is
used by CPU. A process created by the main process is called a child
process

Nahida Nazir 08/01/2021


MCQ

Nahida Nazir 08/01/2021


PROCESS STATES

 New
 Ready
 Running
 Waiting
 Blocked
 Terminated

Nahida Nazir 08/01/2021


STATES

• New - The process is in the stage of being created.


• Ready - The process has all the resources available that it needs to run, but the CPU is not
currently working on this process's instructions.
• Running - The CPU is working on this process's instructions.
• Waiting - The process cannot run at the moment, because it is waiting for some resource to
become available or for some event to occur. For example the process may be waiting for
keyboard input, disk access request, inter-process messages, a timer to go off, or a child
process to finish.
• Terminated - The process has completed.

Nahida Nazir 08/01/2021


DIFFERENT SECTIONS

• The text section comprises the compiled program code, read in from non-volatile storage
when the program is launched.
• The data section stores global and static variables, allocated and initialized prior to executing
main.
• The heap is used for dynamic memory allocation, and is managed via calls to new, delete,
malloc, free, etc.
• .

Nahida Nazir 08/01/2021


CONTINUED

• The stack is used for local variables. Space on the stack is reserved for local variables when
they are declared ( at function entrance or elsewhere, depending on the language ), and the
space is freed up when the variables go out of scope. Note that the stack is also used for
function return values, and the exact mechanisms of stack management may be language
specific.
• Note that the stack and the heap start at opposite ends of the process's free space and grow
towards each other. If they should ever meet, then either a stack overflow error will occur, or
else a call to new or malloc will fail due to insufficient memory available

Nahida Nazir 08/01/2021


PROCESS IN MEMORY

Nahida Nazir 08/01/2021


DIAGRAM OF PROCESS STATE

Nahida Nazir 08/01/2021


 PROCESS CONTROL BLOCK

• Process State - Running, waiting, etc., as discussed above.


• Process ID, and parent process ID.
• CPU registers and Program Counter - These need to be saved and restored when
swapping processes in and out of the CPU.
• CPU-Scheduling information - Such as priority information and pointers to scheduling
queues.

Nahida Nazir 08/01/2021


CONTINUED

•Memory-Management information - E.g. page tables or segment tables.


•Accounting information - user and kernel CPU time consumed, account numbers, limits, etc.
•I/O Status information - Devices allocated, open file tables, etc.

Nahida Nazir 08/01/2021


PCB

Nahida Nazir 08/01/2021


SWITCHING OF THE PROCESSES

Nahida Nazir 08/01/2021


PROCESS SCHEDULING
• The two main objectives of the process scheduling system are to keep the CPU busy at all
times and to deliver "acceptable" response times for all programs, particularly for interactive
ones.
• The process scheduler must meet these objectives by implementing suitable policies for
swapping processes in and out of the CPU.
• ( Note that these objectives can be conflicting. In particular, every time the system steps in to
swap processes it takes up time on the CPU to do so, which is thereby "lost" from doing any
useful productive work. )

Nahida Nazir 08/01/2021


SCHEDULING QUEUES

• All processes are stored in the job queue.


• Processes in the Ready state are placed in the ready queue.
• Processes waiting for a device to become available or to deliver data are placed
in device queues. There is generally a separate device queue for each device.
• Other queues may also be created and used as needed.

Nahida Nazir 08/01/2021


SCHEDULERS

• Long term scheduler


• short term scheduler
• medium scheduler

Nahida Nazir 08/01/2021


SCHEDULAR

• A process migrates between various scheduling queues throughtout its lifetime. The process
of selecting processes from these queues is carried out by a scheduler

Nahida Nazir 08/01/2021


LONG TERM SCHEDULER
Long term scheduler runs less frequently. Long Term Schedulers decide
which program must get into the job queue. From the job queue, the Job
Processor, selects processes and loads them into the memory for
execution. Primary aim of the Job Scheduler is to maintain a good degree
of Multiprogramming. An optimal degree of Multiprogramming means the
average rate of process creation is equal to the average departure rate of
processes from the execution memory

Nahida Nazir 08/01/2021


SHORT TERM SCHEDULER 

This is also known as CPU Scheduler and runs very frequently. The
primary aim of this scheduler is to enhance CPU performance and
increase process execution rate.

Nahida Nazir 08/01/2021


MEDIUM TERM SCHEDULER

Medium Term Scheduler :This scheduler removes the processes from memory (and
from active contention for the CPU), and thus reduces the degree of
multiprogramming. At some later time, the process can be reintroduced into memory
and its execution van be continued where it left off. This scheme is called swapping.
The process is swapped out, and is later swapped in, by the medium term scheduler.

Nahida Nazir 08/01/2021


DISPATCHER

• A dispatcher is a special program which comes into play after the scheduler. When
the scheduler completes its job of selecting a process, it is the dispatcher which takes
that process to the desired state/queue. The dispatcher is the module that gives a
process control over the CPU after it has been selected by the short-term scheduler.
This function involves the following:
• Switching context
• Switching to user mode
• Jumping to the proper location in the user program to restart that program

Nahida Nazir 08/01/2021


DIFFERENCE BETWEEN
SCHEDULER AND DISPATCHER
The Difference between the Scheduler and Dispatcher –
Consider a situation, where various processes are residing in the ready queue waiting
to be executed. The CPU cannot execute all of these processes simultaneously, so the
operating system has to choose a particular process on the basis of the scheduling
algorithm used. So, this procedure of selecting a process among various processes is
done by the scheduler. Once the scheduler has selected a process from the queue,
the dispatcher comes into the picture, and it is the dispatcher who takes that process
from the ready queue and moves it into the running state. Therefore, the scheduler
gives the dispatcher an ordered list of processes which the dispatcher moves to the
CPU over time

Nahida Nazir 08/01/2021


EXAMPLE


There are 4 processes in the ready queue, P1, P2, P3, P4; Their arrival times are t0, t1,
t2, t3 respectively. A First in First out (FIFO) scheduling algorithm is used. Because
P1 arrived first, the scheduler will decide it is the first process that should be executed,
and the dispatcher will remove P1 from the ready queue and give it to the CPU. The
scheduler will then determine P2 to be the next process that should be executed, so
when the dispatcher returns to the queue for a new process, it will take P2 and give it
to the CPU. This continues in the same way for P3, and then P4

Nahida Nazir 08/01/2021


CPU SCHEDULING
CPU Scheduling is a process of determining which process will own
CPU for execution while another process is on hold. The main task of
CPU scheduling is to make sure that whenever the CPU remains idle, the
OS at least select one of the processes available in the ready queue for
execution

Nahida Nazir 08/01/2021


CPU SCHEDULING

Nahida Nazir 08/01/2021


PREEMPTIVE SCHEDULING

In Preemptive Scheduling, the tasks are mostly assigned with their


priorities. Sometimes it is important to run a task with a higher priority
before another lower priority task, even if the lower priority task is still
running. The lower priority task holds for some time and resumes when
the higher priority task finishes its execution

Nahida Nazir 08/01/2021


NON-PREEMPTIVE SCHEDULING

In this type of scheduling method, the CPU has been allocated to a


specific process. The process that keeps the CPU busy will release the
CPU either by switching context or terminating. It is the only method that
can be used for various hardware platforms. That's because it doesn't need
special hardware (for example, a timer) like preemptive scheduling.

Nahida Nazir 08/01/2021


WHEN SCHEDULING IS PREEMPTIVE
OR NON-PREEMPTIVE?

• A process switches from the running to the waiting state.


• Specific process switches from the running state to the ready state.
• Specific process switches from the waiting state to the ready state.
• Process finished its execution and terminated.

Nahida Nazir 08/01/2021


TERMINOLOGY

• Burst Time/Execution Time: It is a time required by the process to complete


execution. It is also called running time.
• Arrival Time: when a process enters in a ready state
• Finish Time: when process complete and exit from a system
• Multiprogramming: A number of programs which can be present in memory at the
same time.

Nahida Nazir 08/01/2021


TERMINOLOGY

• Jobs: It is a type of program without any kind of user interaction.


• User: It is a kind of program having user interaction.
• Process: It is the reference that is used for both job and user.
• CPU/IO burst cycle: Characterizes process execution, which alternates
between CPU and I/O activity. CPU times are usually shorter than the
time of I/O.

Nahida Nazir 08/01/2021


SCHEDULING CRITERIA

Nahida Nazir 08/01/2021


TERMS TO REMEMBER

• CPU utilization: CPU utilization is the main task in which the operating system needs to
make sure that CPU remains as busy as possible. It can range from 0 to 100 percent.
However, for the RTOS, it can be range from 40 percent for low-level and 90 percent for the
high-level system.
• Throughput: The number of processes that finish their execution per unit time is known
Throughput. So, when the CPU is busy executing the process, at that time, work is being
done, and the work completed per unit time is called Throughput.

Nahida Nazir 08/01/2021


TERMS TO REMEMBER

• Minimize:
• Waiting time: Waiting time is an amount that specific process needs to wait in the
ready queue.
• Response time: It is an amount to time in which the request was submitted until the
first response is produced.
• Turnaround Time: Turnaround time is an amount of time to execute a specific
process. It is the calculation of the total time spent waiting to get into the memory,
waiting in the queue and, executing on the CPU. The period between the time of
process submission to the completion time is the turnaround time.

Nahida Nazir 08/01/2021


TYPES OF CPU SCHEDULING ALGORITHM

• There are mainly six types of process scheduling algorithms


• First Come First Serve (FCFS)
• Shortest-Job-First (SJF) Scheduling
• Shortest Remaining Time
• Priority Scheduling
• Round Robin Scheduling
• Multilevel Queue Scheduling

Nahida Nazir 08/01/2021


FIRST COME FIRST SERVE

First Come First Serve is the full form of FCFS. It is the easiest and most
simple CPU scheduling algorithm. In this type of algorithm, the process
which requests the CPU gets the CPU allocation first. This scheduling
method can be managed with a FIFO queue.

Nahida Nazir 08/01/2021


CHARACTERISTICS OF FCFS METHOD:

• It offers non-preemptive and pre-emptive scheduling algorithm.


• Jobs are always executed on a first-come, first-serve basis
• It is easy to implement and use.
• However, this method is poor in performance, and the general wait time is quite
high.

Nahida Nazir 08/01/2021

You might also like