0% found this document useful (0 votes)
93 views84 pages

Chapter 1

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

Chapter 1

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

Course Code

CSE3003

Operating System
Course Objectives
To study and apply concepts relating to operating systems,
such as concurrency and control of asynchronous processes,
deadlocks, memory management, processor scheduling, File
System, Security and Virtualization.
Course Outcomes
• Basics of operating system, its structures and services
• The differences between processes and threads.
• The different process or thread synchronization methods and the tradeoffs between them.
• The different memory management and Scheduling techniques used in Operating Systems.
• Deadlock and solving its related issues
• Various I/O management techniques used in Operating Systems.
• File system and its implementation in storage device.
• The tradeoffs in design and implementation concepts used in the development of
Operating Systems.
• Efficient use of hardware through Virtualization
Unit 1

Basic of Operating System and Its Structures


Introduction: Computer System Organization-
Arhitecture Structure-Operations.
Management:Process-Memory-Storage.
Structures:Services-System Interface- System
Calls- System Program-Design-structure
Unit 2

Process and Threads Introduction to Process –


Scheduling – Operations-Interprocess
Communication. Synchronization: Critical
Section-Hardware Mutex- Semaphore –
Monitors. Threads: Multithreading
ModelsThread Library- Issues
Unit 3

Processor Scheduling and Deadlocks CPU


Scheduling :Scheduling Criteria- Algorithms-
Evaluation. Deadlocks: Principles- Prevention-
Avoidance-Detection Recovery
Unit 4

Memory and Storage Management Main


Memory:Swapping-Contigious Memory
Allocation – Segmentation – Paging. Virtual
Memory:Demand Paging- Page Replacement
Algorithm. Secondary Storage: Disk Scheduling
Disk Management- RAID
Unit 5

File System,I/O and Security File Systems:


Concepts- Structure-Allocation Methods. I/O
Systems:Harware-Interface-Transformation.
Security and Protection:Access Matrix- Access
Control-Program Threats Cryptography-
Defense Mechanism
Unit 1: Introduction
Chapter 1: Introduction
● What Operating Systems Do
● Computer-System Organization
● Computer-System Architecture
● Operating-System Structure
● Operating-System Operations
● Process Management
● Memory Management
● Storage Management
● Protection and Security
● Kernel Data Structures
● Computing Environments
● Open-Source Operating Systems
Objectives
● To describe the basic organization of
computer systems
● To provide a grand tour of the major
components of operating systems
● To give an overview of the many types of
computing environments
● To explore several open-source operating
systems
What is Operating System?
• A program that acts as an intermediary between a user of a
computer and the computer hardware
• OS is a resource allocator
• Manages all resources
• Decides between conflicting requests for efficient and fair resource use
• OS is a control program
• Controls execution of programs to prevent errors and improper use of the
computer
• Operating system goals:
• Execute user programs and make solving user problems easier
• Make the computer system convenient to use
• Use the computer hardware in an efficient manner
Computer System Architecture

• Computer system can be divided into four components:


• Hardware – provides basic computing resources
• CPU, memory, I/O devices
• Operating system
• Controls and coordinates use of hardware among various applications
and users
• Application programs – define the ways in which the system
resources are used to solve the computing problems of the users
• Word processors, compilers, web browsers, database systems, video
games
• Users
• People, machines, other computers
Four Components of a Computer System
What Operating Systems Do
● Depends on the point of view
● Users want convenience, ease of use and good
performance
● Don’t care about resource utilization
● But shared computer such as mainframe or
minicomputer must keep all users happy
● Users of dedicate systems such as workstations
have dedicated resources but frequently use
shared resources from servers
● Handheld computers are resource poor,
optimized for usability and battery life
● Some computers have little or no user interface,
such as embedded computers in devices and
Need for an OS:

• The primary need for the OS arises from the fact that user
needs to be provided with services and OS ought to facilitate
the provisioning of these services.
• The central part of a computer system is a processing engine
called CPU. A system should make it possible for a user’s
application to use the processing unit.
• A user application would need to store information. The OS
makes memory available to an application when required.
• Similarly, user applications need use of input facility to
communicate with the application. This is often in the form of
a key board, or a mouse or even a joy stick (if the application is
a game for instance).
• The OS offers generic services to support all the above
operations. These operations in turn facilitate the
applications.
• To that extent an OS operation is application neutral
and service specific.
Services
Provided by OS
Services provided by OS
• Program Execution
• I/O Operations
• File-System Manipulation
• Communications
• Error Detection
Program Execution
• The OS must be able to load a program into memory and to run that
program. The program must be able to end its execution, either
normally or abnormally.
I/O Operations
• When a program is running it may require I/O. This I/O may involve a
file or an I/O device. A user usually cannot control I/O devices directly.
Therefore the OS system must provide a means to do I/O.
File – System Manipulation
• Programs need to read and write files, programs also need to create
and delete files by name.
Communications

• Sometimes one process needs to exchange information with another


process. Such communication can occur in two major ways. The first
takes place between processes that are executing on the same
computer. The second takes place between process that are executing
on different system that are tied together by a computer network.
Error Detection

• The OS constantly needs to be aware of possible errors. Errors may be


in the CPU and memory hardware, in I/O devices and in the user
program. For each type of error, the OS should take the appropriate
action to ensure correct and consistent computing.
Computer Startup
● bootstrap program is loaded at power-up or
reboot
● For a computer to start running—for instance,
when it is powered up or rebooted—it needs to
have an initial program to run. This initial program,
or bootstrap program, tends to be simple.
Typically, it is stored within the computer
hardware in read-only memory (ROM) or
electrically erasable programmable read-only
memory (EEPROM), generally known as firmware
● Initializes all aspects of system
● Loads operating system kernel and starts
execution
Computer System
Organization
● Computer-system operation
● One or more CPUs, device controllers connect through
common bus providing access to shared memory
● Concurrent execution of CPUs and devices competing for
memory cycles
Computer-System Operation

● I/O devices and the CPU can execute


concurrently
● Each device controller is in charge of a
particular device type
● Each device controller has a local buffer
● CPU moves data from/to main memory
to/from local buffers
● I/O is from the device to local buffer of
controller
● Device controller informs CPU that it has
finished its operation by causing an interrupt
Common Functions of
Interrupts
● Interrupt transfers control to the
interrupt service routine generally,
through the interrupt vector, which
contains the addresses of all the service
routines
● Interrupt architecture must save the
address of the interrupted instruction
● A trap or exception is a software-
generated interrupt caused either by an
error or a user request
● An operating system is interrupt driven
Evolution of Os

29
Evolution of OS:
Evolution of an OS from simple Batch processing to today’s OS-
• Batch Operating System
• Multiprogramming Operating System
• Time Sharing
• Real-Time Systems
• Distributed Operating System

30
31
Batch Processing:
• The users of a batch operating system do not interact
with the computer directly. Each user prepares his job
on an off-line device like punch cards and submits it to
the computer operator.

• To speed up processing, jobs with similar needs are


batched together and run as a group. The
programmers leave their programs with the operator
and the operator then sorts the programs with similar
requirements into batches.

32
33
• In Batch processing same type of jobs batch (BATCH- a set of
jobs with similar needs) together and execute at a time.
• The OS was simple, its major task was to transfer control from
one job to the next.
• The job was submitted to the computer operator in form of
punch cards. At some later time the output appeared.
• The OS was always resident in memory.
• Common Input devices were card readers and tape drives.

34
Common output devices were line printers, tape drives, and card
punches.
Users did not interact directly with the computer systems, but he
prepared a job (comprising of the program, the data, & some
control information).

OS

User
program
area

35
advantages of batch operating system

• You don’t need special hardware and system support to input data in
batch systems.
• Sharing of batch system for multiple users.
• The idle time batch system is very less.
• The batch systems can manage large repeated work easily.

36
The problems with Batch Systems are as follows −

• Lack of interaction between the user and the job.


• CPU is often idle, because the speed of the
mechanical I/O devices is slower than the CPU.
• Difficult to provide the desired priority.

37
• An example of batch processing is the way that credit
card companies process billing. The customer does
not receive a bill for each separate credit card
purchase but one monthly bill for all of that months
purchases. The bill is created through batch
processing, where all of the data are collected and
held until the bill is processed as a batch at the end of
the billing cycle.

38
Multiprogramming:
• Multiprogramming is a technique to execute number of
programs simultaneously by a single processor.
• In Multiprogramming, number of processes reside in main
memory at a time.
• The OS picks and begins to executes one of the jobs in the
main memory.
• If any I/O wait happened in a process, then CPU switches from
that job to another job.
• Hence CPU in not idle at any time.

39
• Multiprogramming is a form of processing in which
several programs are run at the same time on a
uniprocessor. Since there is only one processor, there
can be no true simultaneous execution of different
programs. Instead, the operating system executes part
of one program, then part of another, and so on. To
the user it appears that all programs are executing at
the same time.

40
Multiprogramming
• Figure dipicts the layout of
OS multiprogramming system.
Job 1 • The main memory consists of 5
jobs at a time, the CPU executes
Job 2 one by one.
Advantages:
Job 3
•Efficient memory utilization
Job 4 •Throughput increases

Job 5 •CPU is never idle, so performance


increases.

41
Time Sharing Systems

42
Time Sharing OS:
• Time sharing, or multitasking, is a logical extension of
multiprogramming.
• Multiple jobs are executed by switching the CPU between
them.
• In this, the CPU time is shared by different processes, so it is
called as “Time sharing Systems”.
• Time slice is defined by the OS, for sharing CPU time between
processes.
• Examples: Unix.

43
Process States for Time
Sharing

New Job Execution Terminated


Ready Running

Time Slice over

Wait for I/O


I/O Completed
Completion

Blocked

44
Multitasking

Multitasking is the ability of an operating system to execute more than one task
simultaneously on a single processor machine. Though we say so but in reality
no two tasks on a single processor machine can be executed at the same time.
Actually CPU switches from one task to the next task so quickly that appears as
if all the tasks are executing at the same time. More than one
task/program/job/process can reside into the same CPU at one point of time.

45
Multitasking

Multitasking has the same meaning of multiprogramming but


in a more general sense, as it refers to having multiple
(programs, processes, tasks, threads) running at the same
time. This term is used in modern operating systems when
multiple tasks share a common processing resource (e.g.,
CPU and Memory). At any time the CPU is executing one
task only while other tasks waiting their turn. The illusion of
parallelism is achieved when the CPU is reassigned to
another task (i.e. process or thread context switching).

46
There are suitable differences between multitasking and
multiprogramming. A task in a multitasking operating system
is not a whole application program but it can also refer to a
“thread of execution” when one process is divided into sub-
tasks. Each smaller task does not hijack the CPU until it
finishes like in the older multiprogramming but rather a fair
share amount of the CPU time called quantum.

Just to make it easy to remember, both multiprogramming


and multitasking operating systems are (CPU) time
sharing systems. However, while in multiprogramming
(older OSs) one program as a whole keeps running until it
blocks, in multitasking (modern OSs) time sharing is best
manifested because each running process takes only a fair
quantum of the CPU time.
47
Time-sharing operating system features:

1. Multi-channel nature: That many online


users can simultaneously use the same
computer;

2. Exclusivity: The end-users feel that they


monopolize the computer;

3. Interactivity: Users and computers can be


"conversations."

4. Timeliness: The user's request can be in a


short time to respond. 48
Suppose you are using MS word or MS excel. Now in
these applications many small threads or tasks are running
like spelling checking and grammatical checking in MS
word. So time sharing operating systems have to give time
to these application individual tasks and other applications
also, so that all system behave correctly.

In smartphones the notification bar, songs, weather


forecasting are all running at the same time so time
sharing systems are more efficient to use.

49
Multiprocessing

Multiprocessing is the ability of an operating system to execute more


than one process simultaneously on a multi processor machine. In this,
a computer uses more than one CPU at a time.

50
Multithreading

Multithreading is the ability of an operating system to execute the different


parts of a program called threads at the same time. Threads are the light wait
processes which are independent part of a process or program. In
multithreading system, more than one threads are executed parallely on a
single CPU.

51
What is Real Time Operating System?
• A system that are strictly deadly time bound are called
as real time operating system.
• It has a well defined, fixed time constraints.
• Processing must be done within the defined constraints
or the system will fail.
• A real time system functions correct only if it returns the
correct result within its time constraints.

52
Real time operating system types:-
Types of RTOS.
1. Soft RTOS is a type of system which is less strict to time and
accuracy.
2. Hard RTOS is another type which show exact execution time and
exact output and results on required time.
3. Firm RTOS: Missing a dead line might result in an unacceptable
quality reduction but may not lead to failure of the complete system

For a life saving device, automatic parachute opening device for


skydivers, delay can be fatal. Parachute opening device deploys the
parachute at a specific altitude based on various conditions. If it fails to
respond in specified time, parachute may not get deployed at all
leading to casualty. Similar situation exists during inflation of air bags,
used in cars, at the time of accident. If airbags don’t get inflated at
appropriate time, it may be fatal for a driver. So such systems must be
hard real time systems, whereas for TV live broadcast, delay can be
acceptable. In such cases, soft real time systems can be used.
53
Examples:
Air France Flight 447 crashed into the ocean after a sensor malfunction
caused a series of system errors. The pilots stalled the aircraft while
responding to outdated instrument readings. All 12 crew and 216 passengers
were killed.

Mars Pathfinder spacecraft was nearly lost when a priority inversion caused
system restarts. A higher priority task was not completed on time due to
being blocked by a lower priority task. The problem was corrected and the
spacecraft landed successfully.

An Inkjet printer has a print head with control software for depositing the
correct amount of ink onto a specific part of the paper. If a deadline is missed
then the print job is ruined.

54
Jitter in real time operating systems

55
Jitter:-
Jitter is a term used for the amount of errors and gap
between subsequent loops and operation of same task i.e.
suppose if four same tasks are run in a loop then the time
gap between completion of these tasks or the difference in
time of execution of each task is known as jitter. So in soft
RTOS there is some jitter found while in hard RTOS there
is no or very little chance of Jitter.

Real time operating system are usually event driven and


strict. For example these operating system have to
response immediately when some event or interrupt
occurs.
56
Advantages of Real Time Operating System:-

Maximum Consumption: – RTOS give maximum consumption of the


system and gives us more output while using all the resources and
keeping all devices active. There is little or no down time in these
systems. So it can be also using by the servers that are hosted to give
maximum output of hosting companies.

Task Shifting: – There is very little time assigned to shifting tasks in


these systems. For example in older systems it takes about 10 micro
seconds in shifting one task to another and in latest systems it takes 3
micro seconds.

Focus on Application: – These type of operating system focus on


applications which are running and usually give less importance to other
application residing in waiting stage of life cycle. So less applications or
tasks are managed and give exact result on current execution work.

57
Real time operating system in embedded system: – Due to small
size of programs RTOS can also be used in embedded systems like in
transport and others.

Error Free: – RTOS is error free that mean it has no chances of error
in performing tasks.

24-7 systems: – RTOS can be best used for any applications which
run 24 hours and 7 days because it do less task shifting and give
maximum output.

Real time operating system examples: – There are many real time
operating system examples. They are used in vast areas like digital
appliances, home video games, wind power systems, intelligent
transport system, and robots in industry

Memory Allocation: – Memory allocation is best managed in these


type of systems.
58
Disadvantages of Real Time Operating System:

Limited Tasks: – There are only limited tasks run at the same time and the
concentration of these system are on few application to avoid errors and other
task have to wait. Sometime there is no time limit of how much the waiting tasks
have to wait.

Use heavy system resources: – RTOS used lot of system resources which is
not as good and is also expensive.

Low multi-tasking: – Multi tasking is done few of times and this is the main
disadvantage of RTOS because these system runs few tasks and stay focused
on them. So it is not best for systems which use lot of multi-threading because of
poor thread priority.

Complex Algorithms: – RTOS uses complex algorithms to achieve a desired


output and it is very difficult to write that algorithms for a designer.

Device driver and interrupt signals: – RTOS must need specific device drivers
and interrupt signals to response fast to interrupts.
59
Thread Priority: – Thread priority is not good as RTOS do less
switching of tasks.

Expensive: – RTOS are usually very expensive because of the


resources they need to work.

Not easy to program: – The designer have to write proficient program


for real time operating system which is not easy as a piece of cake.

Low Priority Tasks: – The low priority tasks may not get time to run
because these systems have to keep accuracy of current running
programs.

Precision of code: – Event handling of tasks is strict so more


precision in code needed for designer to program. Event must be
responded quickly and this is not easy for exact precision for the
designer.
60
Distributed Systems:
• A distributed computer system is a collection of autonomous computer
systems capable of communication and cooperation via their H/w and S/w
interconnection.
• The distributed operating system provides a illusion to its users that it has a
single uniprocessor system, although it is actually consists of multiprocessors.
• Distributed OS provide the means for system-wide sharing of resources such
as computational capacity, files and I/O devices.
• Ex: UNIX, LINUX.

61
What is a distributed system?
• A distributed system is a collection of independent computers that appear to
the users of the system as a single system.
• Examples:
• Network of workstations
• Network of branch office computers

62
Advantages of Distributed Systems
over Independent PCs
• Data sharing: allow many users to access to a common data base
• Resource Sharing: expensive peripherals like color printers
• Communication: enhance human-to-human communication, e.g., email, chat
• Flexibility: spread the workload over the available machines

63
Disadvantages of Distributed Systems

• Software: difficult to develop software for distributed systems


• Network: saturation, lossy transmissions
• Security: easy access also applies to secret data

64
Examples of distributed systems and applications of
distributed computing include the following:

• telecommunication networks: telephone networks and cellular


networks, ...
• network applications: World wide web and peer-to-peer
networks, ...
• real-time process control: aircraft control systems, ...

65
System Calls
• Definition: System calls are requests made by a
program to the operating system kernel for performing
various operations, such as file I/O, process
management, memory allocation, and more.
• Purpose: They provide a way for user-level processes
to interact with the operating system kernel and access
privileged resources.
• Isolation: System calls often involve a switch from user
mode to kernel mode, which involves a transition
between user space and kernel space, ensuring that
certain operations are performed with the necessary
permissions.
System calls are generally used for tasks that require
interaction with the underlying hardware or resources
managed by the operating system.
Types of System Calls

• Process Control

• File Manipulation

• Device Management

• Information Maintenance

• Communication
Process Control
• fork(): Create a new process by duplicating the existing process.
• exec(): Replace the current process's memory image with a new
program.
• exit(): Terminate the calling process and return the exit status to
the parent process.
File Manipulation
• open(): Open a file or create a new one.
• close(): Close a file descriptor.
• read(): Read data from a file.
• write(): Write data to a file.
• lseek(): Move the file pointer within a file.
Device Manipulation
• ioctl(): Perform I/O control operations on devices.
• read(): Read data from a device.
• write(): Write data to a device.
Information Maintenance
• getpid(): Get the process ID of the calling process.
• getppid(): Get the parent process ID.
• getuid(): Get the user ID of the calling process.
• getgid(): Get the group ID of the calling process.
Communication
• pipe(): Create a pipe for one-way communication
between processes.
• msgsnd() and msgrcv(): Send and receive messages
between processes using message queues.
• semctl(), semget(), and semop(): Perform
operations on semaphores for process synchronization.
Memory Management
• brk() and sbrk(): Set the end of the data segment to
allocate memory dynamically.
• mmap() and munmap(): Map or unmap files or
devices into memory.
Time
• time(): Get the current time.
• sleep(): Suspend the execution of a process for a
specified time.
Network Management (for network-
aware operating systems):
• socket(): Create a new communication endpoint
(socket).
• connect(): Establish a connection to a remote socket.
• send() and recv(): Send and receive data over a
socket.
Threads
• Definition: A thread is the smallest unit of execution
within a process. Multiple threads can exist within a
single process, and they share the same resources, such
as memory space and file descriptors.
• Purpose: Threads allow for concurrent execution of
tasks within a process, enabling parallelism and
improved performance.
• Isolation: Threads within the same process share the
same address space, which means they can directly
access each other's data. This shared memory space
simplifies communication between threads but also
requires synchronization mechanisms to avoid conflicts.
Kernel
• A kernel is a crucial component of an operating system
(OS) that acts as an intermediary between the
hardware and the user-level applications.
• It provides essential services and manages system
resources to enable the execution of programs and the
overall functioning of the computer.
• The kernel is loaded into memory when the computer
starts, and it remains resident in memory throughout
the computer's operation.
Key Functions of kernel
Process Management:
[Link] and termination of processes.
[Link] processes to execute on the CPU.
[Link] communication and
synchronization.
Memory Management:
[Link] and deallocation of memory for
processes.
[Link] memory management, including
paging and segmentation.
File System Management:
[Link] of files, directories, and storage
devices.
Device Drivers:
1. Communication with hardware devices such as disks,
network interfaces, and input/output devices.
2. Providing a standardized interface for applications to
interact with hardware.
Security and Access Control:
3. Enforcing access control policies to regulate user and
application access to resources.
4. Handling authentication and authorization.
System Calls:
5. Providing an interface for user-level applications to
request services from the kernel (system calls).
Interrupt Handling:
6. Responding to hardware and software interrupts.
7. Managing exceptions and errors.
Networking:
1. Handling network-related operations, such as socket management and
network protocol processing.
Fork()

int main()
{
fork();
fork();
fork();
printf("hello\n");
return 0;
}

How many times it will print ”hello” in the output?


Main ()
{
if (fork() && (!fork()))
{
if (fork() ll fork())
{
Fork();
}
}
Printf(“ *”);
Return 0
}

Output:- *******
• Explanation:
1. Fork will create two process one parent P (has process id of
new child) and other one is child C1 (process id=0).
2. In if statement we are using AND operator (i.e, &&) and in
this case if first condition is false then it will not evaluate
second condition and print *. Parent process P check for second
condition and create two new processes (one parent P and
other is child C2).
In second condition we are using NOT operator which return true
for child process C2 and it executes inner if statement.
3. Child C2 again create two new processes (one parent C2 and
child C3) and we are using OR operator (i.e, ||) which evaluate
second condition when first condition is false.
Parent C2 execute if part and create two new processes (one
parent C2 and child C4) whereas child C3 check for second
condition and create two new processes (one parent C3 and child
C5).

4. Parent C3 enters in if part and further create two new


processes (one parent C3 and child C6).
Thank You

You might also like