0% found this document useful (0 votes)
6 views

02 Fundamentals

The document discusses the boot process of a computer and the role of the kernel in initializing system components and loading the operating system. It describes how the kernel is the core of the operating system and facilitates communication between hardware and software. It also discusses the different modes of operation and how system calls allow programs to interface with the operating system.

Uploaded by

khaledhamead
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)
6 views

02 Fundamentals

The document discusses the boot process of a computer and the role of the kernel in initializing system components and loading the operating system. It describes how the kernel is the core of the operating system and facilitates communication between hardware and software. It also discusses the different modes of operation and how system calls allow programs to interface with the operating system.

Uploaded by

khaledhamead
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
You are on page 1/ 33

Operating Systems 1

CS 241
Spring 2021

By
Marwa M. A. Elfattah

Main Reference
Operating System Concepts, Abraham Silbrschatz,
10th Edition
Fundamentals
When you power up a computer, what happens?
 For a computer to start it needs to have an initial
simple program to run – bootstrap - bootloader.
• It is stored within the computer hardware in
firmware (BIOS).
 It initializes all aspects of the system
 It must locate the operating-system kernel and load
it into memory.
 Once the kernel is loaded and executing, it can start
providing services.
 Then, the system is fully booted, and the system
waits for some event to occur.
When you power up a computer, what happens?
 For a computer to start it needs to have an initial
simple program to run – bootstrap - bootloader.
• It is stored within the computer hardware in
firmware (BIOS).
 It initializes all aspects of the system
 It must locate the operating-system kernel and load
it into memory. What is the
 Once the kernel is loaded and
Kernel?
executing, it can start
providing services.
 Then, the system is fully booted, and the system
waits for some event to occur.
Operating System Kernel
 “The one program running at all times on the
computer” is the kernel, part of the operating
system
 Everything else is either
• A system services – system utility (ships with
the operating system, but not part of the kernel),
such as: file manipulation, status information,
background services,…
• An application program, all programs not
associated with the operating system
Operating System Kernel
 A system cannot function without the Operating
System, and an Operating System cannot exist
without the Kernel.
 Kernel is the operating system core. It functions at
the lowest level of the operating system
 It is a programs which is close to the hardware of
the system and so,
• It performs all the tasks of the operating systems
which involve a link between both the hardware
and the user level applications.
Dual Mode

A computer operates in two modes, systems


frequently switch between them.
Kernel Mode Versus User Mode
 When the computer is running application software,
it is in user mode.
• It is also known as less privileged mode, slave
mode or restricted mode.
Kernel Mode Versus User Mode
 After the application software request for hardware,
the computer enters kernel mode.
• Kernel mode is also called as system
mode or privileged mode.
• If a process in kernel mode fails the entire
operating system might fail.
Kernel Mode Versus User Mode
 Mode bit - provided by hardware - provides ability
to distinguish when system is running user code or
kernel code
 System call and interrupts changes mode to
kernel, return from call resets it to user
Kernel Mode Versus User Mode
 Mode bit - provided by hardware - provides ability
System
to distinguish when system is running call?
user code or
kernel code Interrupt?
 System call and interrupts changes mode to
kernel, return from call resets it to user
System Calls
 System calls provide the means for a user program
to ask the operating system to perform tasks
Programming interface to the services provided
by the OS
 EX: How to read data from one file and copy them to
another file?
• Users can use:
command like: cp in.txt out.txt
mouse-based and icon-based systems
…

• To do so system call sequence can be:


System Calls
 System calls provide the means for a user program
Write system
to ask the operating prompt to
toperform
screentasks
Accept input //input file name
Programming
Writeinterface
prompt to tothe services provided
screen
by the OSAccept input //output file name
Open the input file
 EX: How to read data from one file and copy them to
if file doesn't exist, abort
another file? Create output file
• Users can use:
if file exists, abort
Loop
command like: cp in.txt out.txt
Read from input file
mouse-basedWrite to output
and icon-based file
systems
… Until read fails
Close output file
• To do so system
Write call sequencemessage
completion can be: to screen
Terminate normally
System Calls
 Most developers design programs according to an
application programming interface (API).
need know nothing about how the system call is
implemented or what it does during execution.
only obey the API and understand what will be a result.
The API specifies a set of functions that are
available to an application programmer

System calls can often be more detailed and


difficult to work with

 Run-time environment (RTE) provides system-call


interface that serves as the link to system calls
made available by the operating system.
System Calls
The standard C
library is an example
of a portion of the
system-call interface.
If printf() is invoked.
The C library intercepts
this call and invokes
the necessary system
call (or calls).
The C library takes the
value returned and
passes it back to the
user program
System Calls Handling
 The system-call interface intercepts function calls in
the API and invokes the necessary system calls
within the operating system.
• A number is associated with each system call
• System-call interface maintains a table indexed
according to these numbers
• The system call interface invokes the intended
system call in OS kernel and returns status of the
system call and any return values
Open() System Call
System Calls Handling
 System call parameters can be passed to the
operating system in three different ways:
• In registers.
There may be more parameters than registers.
• In a block, or table, in memory, and the address of
the block is passed as a parameter in a register.
Linux uses a combination of these approaches. If there
are five or fewer parameters registers are used,
otherwise memory block used
• Pushed, onto a stack by the program and popped
off the stack by the operating system.
Why Applications are Operating System Specific
 Apps compiled on one system usually not
executable on other operating systems
 Each operating system provides its own unique
system calls, own file formats, etc
 Apps can be multi-operating system
• Written in interpreted language like Python,
Ruby, and interpreter available on multiple
operating systems
• App written in language that includes a VM
containing the running app (like Java)
• Use standard language (like C), compile
separately on each operating system to run on
each.
Why Applications are Operating System Specific
 Apps compiled on one system usually not
executable on other operating systems
 Each operating system provides its own unique
system calls,What
own file is the etc
formats,
 Apps can be multi-operating system
Interrupt?
• Written in interpreted language like Python,
Ruby, and interpreter available on multiple
operating systems
• App written in language that includes a VM
containing the running app (like Java)
• Use standard language (like C), compile
separately on each operating system to run on
each.
Interrupts
 Interrupts are a key way in which hardware interacts
with the operating system.
 The CPU hardware has a wire called the interrupt-
request line
 A hardware device triggers an interrupt by sending a
signal to the CPU to alert the CPU that some event
requires attention.
 A trap or exception is a software interrupt
Software error (e.g., division by zero)
Or request process problems include infinite
loop, processes modifying each other or the
operating system,…
Interrupts
 The interrupt is managed by a separated segments
of code determine what action should be taken for
each type of interrupt - interrupt handler.
• The operating system preserves the state of the
CPU by storing the registers and the program
counter
• Determines which type of interrupt has occurred:
• The interrupt must transfer control to the
appropriate interrupt service routine, through:
a generic routine
or interrupt vector, to speed up and reduce searching
Example
Example
Example
Example
But, How Operating System
is Implemented??
Operating System Implementation
 A system as large and complex as a modern
operating system must be engineered carefully if it is
to function properly and be modified easily.
 A common approach is to partition the task into
small components, or modules, rather than have
one single system.
Each of these modules should be a well-defined
portion of the system, with carefully defined
interfaces and functions.
Operating System Implementation
 Early operating systems were written in assembly
language.
 Now, The lowest levels of the kernel might be written
in assembly language and C. Higher-level routines
might be written in C and C++, and system libraries
might be written in C++ or even higher-level
languages.
 Android provides a nice example:
Itskernel is written mostly in C with some assembly
language.
Most Android system libraries are written in C or C++.
Itsapplication frameworks—which provide the developer
interface to the system—are written mostly in Java.
Thank You

You might also like