Os Unit1
Os Unit1
Os Unit1
SYSTEM
Dr. Sudharson D
Dept of AI&DS
KSI
KCT
Course Objective
• To learn the mechanisms of OS to handle processes and threads and
their Communication
• To learn the mechanisms involved in memory management in
contemporary OS
• To gain knowledge on distributed operating system concepts that
includes architecture, Mutual exclusion algorithms, deadlock
detection algorithms and agreement protocols
• To know concept and working principle of open-source OS
Course Outcome
• CO1: Apply the concepts of CPU scheduling and Process
synchronization
• CO 2: Experiment creation of different virtual machines in a
hypervisor
• CO 3: Simulate the principles of memory management
• CO 4: Examine the features of various open source operating systems
Unit1- Introduction and Process Concept
Operating System Structure - Operating System Operations - Process
Management - Memory Management - Storage Management -
Protection and Security - System Structures: Operating System Services
- User and Operating System Interface - System Calls - Types of System
Calls - Process Scheduling - Operations on Processes - Inter-process
Communication.
Operating System Structure
• An operating system is a design that enables user application
programs to communicate with the hardware of the machine.
• The operating system should be built with the utmost care because it
is such a complicated structure and should be simple to use and
modify.
• Partially developing the operating system is a simple approach to
accomplish this.
• Each of these components needs to have distinct inputs, outputs, and
functionalities.
Operating System Structure
• There are four layers that make up the MS-DOS operating system, and each has its own set of
features.
• These layers include ROM BIOS device drivers, MS-DOS device drivers, application programs, and
system programs.
• The MS-DOS operating system benefits from layering because each level can be defined
independently and, when necessary, can interact with one another.
• If the system is built in layers, it will be simpler to design, manage, and update. Because of this,
simple structures can be used to build constrained systems that are less complex.
• When a user program fails, the operating system as whole crashes.
• Because MS-DOS systems have a low level of abstraction, programs and I/O procedures are visible
to end users, giving them the potential for unwanted access.
Operating System Structure
Operating System Structure
Operating System Operations
• The major operations of
the operating system are
process management,
memory management,
device management and
file management.
Process Management
• The operating system is responsible for managing the processes
i.e assigning the processor to a process at a time. This is known
as process scheduling.
• The different algorithms used for process scheduling are FCFS
(first come first served), SJF (shortest job first), priority
scheduling, round robin scheduling etc.
• There are many scheduling queues that are used to handle
processes in process management. When the processes enter the
system, they are put into the job queue.
• The processes that are ready to execute in the main memory are
kept in the ready queue. The processes that are waiting for the
I/O device are kept in the device queue.
Process Management
• Attributes or Characteristics of a Process
• Process Id: A unique identifier assigned by the operating system
• Process State: Can be ready, running, etc.
• CPU registers: Like the Program Counter (CPU registers must be saved and restored when
a process is swapped in and out of the CPU)
• Accounts information: Amount of CPU used for process execution, time limits, execution
ID, etc
• I/O status information: For example, devices allocated to the process, open files, etc
• CPU scheduling information: For example, Priority (Different processes may have
different priorities, for example, a shorter process assigned high priority in the shortest
job first scheduling)
• All of the above attributes of a process are also known as the context of the process.
Every process has its own process control block(PCB), i.e. each process will have a unique
PCB. All of the above attributes are part of the PCB.
Process Management
Memory Management
• The term memory can be defined as a collection of data in a specific
format. It is used to store instructions and process data. The memory
comprises a large array or group of words or bytes, each with its own
location.
• The primary purpose of a computer system is to execute programs.
These programs, along with the information they access, should be in
the main memory during execution.
• The task of subdividing the memory among different processes is
called Memory Management.
Memory Management
• Main memory is
associated with the
processor, so moving
instructions and
information into and out
of the processor is
extremely fast.
• Main memory is also
known as RAM (Random
Access Memory).
Memory Management
• Logical Address Space: An address generated by the CPU is known as
a “Logical Address”. It is also known as a Virtual address.
• A Physical address is also known as a Real address. The set of all
physical addresses corresponding to these logical addresses is known
as Physical address space. A physical address is computed by MMU.
• Static Loading: Static Loading is basically loading the entire program
into a fixed address. It requires more memory space.
• Dynamic Loading: The entire program and all data of a process must
be in physical memory for the process to execute. So, the size of a
process is limited to the size of physical memory.
Memory Management
• Static Linking: In static linking, the linker combines all necessary
program modules into a single executable program. So there is no
runtime dependency. Some operating systems support only static
linking, in which system language libraries are treated like any other
object module.
• Dynamic Linking: The basic concept of dynamic linking is similar to
dynamic loading. In dynamic linking, “Stub” is included for each
appropriate library routine reference. A stub is a small piece of code.
When the stub is executed, it checks whether the needed routine is
already in memory or not. If not available then the program loads the
routine into memory.
Memory Management
• Swapping is a process of swapping a process temporarily into a
secondary memory from the main memory, which is fast compared to
secondary memory.
• The main memory should accommodate both the operating
system and the different client processes. Therefore, the allocation of
memory becomes an important task in the operating system.
Memory Management
Memory Management
• Fragmentation is defined as when the process is loaded and
removed after execution from memory, it creates a small free
hole.
• Internal fragmentation: Internal fragmentation occurs when
memory blocks are allocated to the process more than their
requested size. Due to this some unused space is left over
and creating an internal fragmentation problem
• External fragmentation: In External Fragmentation, we have
a free memory block, but we can not assign it to a process
because blocks are not contiguous.
Storage Management
• Paging is a memory management scheme that eliminates the need for a
contiguous allocation of physical memory. This scheme permits the physical
address space of a process to be non-contiguous.
• Logical Address or Virtual Address (represented in bits): An address
generated by the CPU.
• Logical Address Space or Virtual Address Space (represented in words or
bytes): The set of all logical addresses generated by a program.
• Physical Address (represented in bits): An address actually available on a
memory unit.
• Physical Address Space (represented in words or bytes): The set of all
physical addresses corresponding to the logical addresses.
Storage Management
Storage Management
Segmentation
• This is a memory management
technique that supports the user view of
memory.
• The logical address space is divided into
a group of segments.
• These segments have a name and
memory length.
• So, the segment address is specifies
using its name, base address and length.
Storage Management
Virtual Memory
The most important concepts in virtual memory are demand paging and thrashing.
Details about these topics are given below −
Demand Paging
• A demand paging basically contains paging with swapping. A page of the process is
only brought into the main memory if it is required.
• The steps required for demand paging are −
• Check if the page demand was for a valid memory access or not.
• If the reference was invalid, the process is terminated. However, if the reference was
valid and the page is not available in main memory, then it is brought in.
• First a free frame is found and then the required page is read into the frame.
• Then the internal page table is modified to direct that the required page is now
available in main memory.
• After all this, the process can access the page as if it was always available in the
memory.
Storage Management
Storage Management
• Thrashing
• Thrashing occurs when there are not enough frames for a
process process.
• Suppose all the pages of a process in main memory are in
active use.
• If it requires another page from secondary memory, then it
needs to replace a page.
• However the replaces page was also active and it is brought
back into the memory by replacing yet another page.
• So if there is more paging than processing going on in the
system, then thrashing has occurred.
Protection and Security
• Threats
• Virus
• Viruses are generally small snippets of code embedded in a system. They are very dangerous and can corrupt files, destroy data,
crash systems etc. They can also spread further by replicating themselves as required.
• Trojan Horse
• A trojan horse can secretly access the login details of a system. Then a malicious user can use these to enter the system as a
harmless being and wreak havoc.
• Trap Door
• A trap door is a security breach that may be present in a system without the knowledge of the users. It can be exploited to harm
the data or files in a system by malicious people.
• Worm
• A worm can destroy a system by using its resources to extreme levels. It can generate multiple copies which claim all the
resources and don't allow any other processes to access them. A worm can shut down a whole network in this way.
• Denial of Service
• These type of attacks do not allow the legitimate users to access a system. It overwhelms the system with requests so it is
overwhelmed and cannot work properly for other user.
Protection and Security
• Authentication
• This deals with identifying each user in the system and making sure they are
who they claim to be. The operating system makes sure that all the users are
authenticated before they access the system.
• One Time Password
• These passwords provide a lot of security for authentication purposes. A one
time password can be generated exclusively for a login every time a user
wants to enter the system
System Structures: Operating System Services
• Program execution
• Control Input/output devices
• Program creation
• Error Detection and Response
• Accounting
• Security and Protection
• File Management
• Communication
User and Operating System Interface
• Command line interface
• The command-line interface is an interface whenever the user needs
to have different commands regarding the input and output and then a
task is performed so this is called the command-line argument and it is
used to execute the output and create, delete, print, copy, paste, etc.
• Command Line Interface advantages
• Controls OS or application
• faster management
• ability to store scripts which helps in automating regular tasks.
• Troubleshoot network connection issues.
• GUI (Graphical User Interface): Visual user interface output (keyboard and monitor) with a tactile
user interface input.
• Menu Driven Interface: An UI that uses a menu of options to navigate a program or website is
known as a menu-driven UI. For instance, ATMs have user interfaces that are menu-driven and
simple to use.
• Form Based Interface: Form-based user interfaces provide a small number of options for users to
choose from when entering data into a program or application. For instance, a device’s settings
menu is form-based.
• Touch user interface: Haptic or tactile user interface. Haptic input is used by most smartphones,
tablets, and other devices with touch screens.
• Voice user interface: Auditory commands are used to communicate between humans and
machines. GPS, talk-to-text gadgets, and virtual assistants are a few examples.
System Structures: Operating System Services
• Information Maintenance
• Information maintenance is a system call that is used to maintain
information.
• There are some examples of information maintenance, including getting
system data, set time or date, get time or date, set system data, etc.
• Communication
• Communication is a system call that is used for communication.
• There are some examples of communication, including create, delete
communication connections, send, receive messages, etc.
Types of System Calls
• Process Control
• Process control is the system call that is used to direct the processes. Some
process control examples include creating, load, abort, end, execute, process,
terminate the process, etc.
• File Management
• File management is a system call that is used to handle the files. Some file
management examples include creating files, delete files, open, close, read,
write, etc.
• Device Management
• Device management is a system call that is used to deal with devices. Some
examples of device management include read, device, write, get device
attributes, release device, etc.
Process Scheduling
• Activity of the process manager that handles the
removal of the running process from the CPU and the
selection of another process on the basis of a particular
strategy.
• Process scheduling is an essential part of a
Multiprogramming operating systems.
• Such operating systems allow more than one process to
be loaded into the executable memory at a time and
the loaded process shares the CPU using time
multiplexing.
Process Scheduling
• There are two categories of scheduling:
• Non-preemptive: Here the resource can’t be taken
from a process until the process completes execution.
The switching of resources occurs when the running
process terminates and moves to a waiting state.
• Preemptive: Here the OS allocates the resources to a
process for a fixed amount of time. During resource
allocation, the process switches from running state to
ready state or from waiting state to ready state. This
switching occurs as the CPU may give priority to other
processes and replace the process with higher priority
with the running process.
Process Scheduling
• The OS maintains all Process Control Blocks (PCBs) in Process
Scheduling Queues.
• Job queue − This queue keeps all the processes in the
system.
• Ready queue − This queue keeps a set of all processes
residing in main memory, ready and waiting to execute. A new
process is always put in this queue.
• Device queues − The processes which are blocked due to
unavailability of an I/O device constitute this queue.
Process Scheduling
• Two-State Process Model
• Two-state process model refers to running and non-running states which are
described below
• Running
• When a new process is created, it enters into the system as in the running
state.
• Not Running
• Processes that are not running are kept in queue, waiting for their turn to
execute. Each entry in the queue is a pointer to a particular process. Queue is
implemented by using linked list. Use of dispatcher is as follows. When a
process is interrupted, that process is transferred in the waiting queue. If the
process has completed or aborted, the process is discarded. In either case,
the dispatcher then selects a process from the queue to execute.
Process Scheduling
• Context switches are computationally intensive since register and
memory state must be saved and restored. To avoid the amount of
context switching time, some hardware systems employ two or more
sets of processor registers. When the process is switched, the
following information is stored for later use.
• Program Counter
• Scheduling information
• Base and limit register value
• Currently used register
• Changed State
• I/O State information
• Accounting information
Process Scheduling
• Context Switching
• A context switching is the
mechanism to store and
restore the state or
context of a CPU in
Process Control block so
that a process execution
can be resumed from the
same point at a later time
Process Scheduling
S.N
. Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler
1 It is a job scheduler It is a CPU scheduler It is a process swapping scheduler.
2 Speed is lesser than short term scheduler Speed is fastest among other two Speed is in between both short and long term
scheduler.
3 It controls the degree of multiprogramming It provides lesser control over degree of It reduces the degree of multiprogramming.
multiprogramming
4 It is almost absent or minimal in time It is also minimal in time sharing system It is a part of Time sharing systems.
sharing system
5 It selects processes from pool and loads It selects those processes which are ready It can re-introduce the process into memory
them into memory for execution to execute and execution can be continued.
Process Scheduling
• Context switches are computationally intensive since register and
memory state must be saved and restored. To avoid the amount
of context switching time, some hardware systems employ two
or more sets of processor registers. When the process is
switched, the following information is stored for later use.
• Program Counter
• Scheduling information
• Base and limit register value
• Currently used register
• Changed State
• I/O State information
• Accounting information
Operations on Processes
• A process may be created by another process using fork(). The creating
process is called the parent process and the created process is the child
process
Operations on process
• Process Preemption
• An interrupt mechanism is
used in preemption that
suspends the process
executing currently and the
next process to execute is
determined by the short-
term scheduler. Preemption
makes sure that all
processes get some CPU
time for execution.
• A diagram that
demonstrates process
preemption is as follows −
Operations on process
• Process Blocking
• The process is blocked if it is
waiting for some event to occur.
This event may be I/O as the I/O
events are executed in the main
memory and don't require the
processor. After the event is
complete, the process again
goes to the ready state.
Operations on process
• Process Termination
• After the process has completed the execution of its last
instruction, it is terminated. The resources held by a process are
released after it is terminated.
• A child process can be terminated by its parent process if its
task is no longer relevant. The child process sends its status
information to the parent process before it terminates. Also,
when a parent process is terminated, its child processes are
terminated as well as the child processes cannot run if the
parent processes are terminated.
Inter-process Communication.
• Interprocess communication is the mechanism provided
by the operating system that allows processes to
communicate with each other. This communication
could involve a process letting another process know
that some event has occurred or the transferring of
data from one process to another.
Inter-process Communication.
Synchronization in Interprocess Communication
• Synchronization is a necessary part of interprocess communication. It is either provided by the
interprocess control mechanism or handled by the communicating processes. Some of the methods
to provide synchronization are as follows
• Semaphore
• A semaphore is a variable that controls the access to a common resource by multiple processes.
The two types of semaphores are binary semaphores and counting semaphores.
• Mutual Exclusion
• Mutual exclusion requires that only one process thread can enter the critical section at a time. This
is useful for synchronization and also prevents race conditions.
• Barrier
• A barrier does not allow individual processes to proceed until all the processes reach it. Many
parallel languages and collective routines impose barriers.
• Spinlock
• This is a type of lock. The processes trying to acquire this lock wait in a loop while checking if the
lock is available or not. This is known as busy waiting because the process is not doing any useful
operation even though it is active.
Inter-process Communication.
• Approaches to Interprocess Communication
• Pipe
• A pipe is a data channel that is unidirectional. Two pipes can be used to create a two-way data
channel between two processes. This uses standard input and output methods. Pipes are used in
all POSIX systems as well as Windows operating systems.
• Socket
• The socket is the endpoint for sending or receiving data in a network. This is true for data sent
between processes on the same computer or data sent between different computers on the same
network. Most of the operating systems use sockets for interprocess communication.
• File
• A file is a data record that may be stored on a disk or acquired on demand by a file server.
Multiple processes can access a file as required. All operating systems use files for data storage.
Inter-process Communication.
Inter-process Communication.
• Approaches to Interprocess Communication
• Signal
• Signals are useful in interprocess communication in a limited way. They are system
messages that are sent from one process to another. Normally, signals are not used to
transfer data but are used for remote commands between processes.
• Shared Memory
• Shared memory is the memory that can be simultaneously accessed by multiple
processes. This is done so that the processes can communicate with each other. All
POSIX systems, as well as Windows operating systems use shared memory.
• Message Queue
• Multiple processes can read and write data to the message queue without being
connected to each other. Messages are stored in the queue until their recipient
retrieves them. Message queues are quite useful for interprocess communication and
are used by most operating systems.
MULTITHREADED PROGRAMMING
AND PROCESS SCHEDULING
• Overview of threads - Multicore programming - Multithreading
Models - Threading Issues - Basic Concepts of process scheduling -
Scheduling Criteria - Scheduling Algorithms - Multiple Processor
Scheduling - Synchronization - The Critical-Section Problem
- Peterson’s Solution Synchronization Hardware - Semaphores - Classic
problems of Synchronization - Monitors