SlideShare a Scribd company logo
2.1 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Operating system
Week 5
BSIT 4th
2.2 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
System Calls
 A system call is a function that a user program uses to ask the
operating system for a particular service. User programmers
can communicate with the operating system to request its
services using the interface that is created by a system call.
 Programming interface to the services provided by the OS
 Typically written in a high-level language (C or C++)
 Mostly accessed by programs via a high-level Application
Programming Interface (API) rather than direct system call use
 Three most common APIs are Win32 API for Windows, POSIX API
for POSIX-based systems (including virtually all versions of UNIX,
Linux, and Mac OS X), and Java API for the Java virtual machine
(JVM)
 Why use APIs rather than system calls?
2.3 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Example of System Calls
 System call sequence to copy the contents of one file to another file
2.4 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Example of Standard API
2.5 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 Why do you need system calls in Operating
System?
 There are various situations where you must require system calls in the
operating system. Following of the situations are as follows:
1. It is must require when a file system wants to create or delete a file.
2. Network connections require the system calls to sending and receiving data
packets.
3. If you want to read or write a file, you need to system calls.
4. If you want to access hardware devices, including a printer, scanner, you
need a system call.
5. System calls are used to create and manage new processes.
2.6 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
System Call Implementation
 Typically, a number associated with each system call
 System-call interface maintains a table indexed according to
these numbers
 The system call interface invokes intended system call in OS kernel
and returns status of the system call and any return values
 The caller need know nothing about how the system call is
implemented
 Just needs to obey API and understand what OS will do as a
result call
 Most details of OS interface hidden from programmer by API
 Managed by run-time support library (set of functions built into
libraries included with compiler)
2.7 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
How System Calls Work
 The Applications run in an area of memory known as user
space.
 A system call connects to the operating system's kernel,
which executes in kernel space.
 When an application creates a system call, it must first obtain
permission from the kernel. It achieves this using an interrupt
request, which pauses the current process and transfers
control to the kernel.
 If the request is permitted, the kernel performs the requested
action, like creating or deleting a file. As input, the application
receives the kernel's output. The application resumes the
procedure after the input is received. When the operation is
finished, the kernel returns the results to the application and
then moves data from kernel space to user space in memory.
2.8 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
API – System Call – OS Relationship
2.9 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
System Call Parameter Passing
 Often, more information is required than simply identity of desired
system call
 Exact type and amount of information vary according to OS and
call
 Three general methods used to pass parameters to the OS
 Simplest: pass the parameters in registers
 In some cases, may be more parameters than registers
 Parameters stored in a block, or table, in memory, and address of
block passed as a parameter in a register
 This approach taken by Linux and Solaris
 Parameters placed, or pushed, onto the stack by the program and
popped off the stack by the operating system
 Block and stack methods do not limit the number or length of
parameters being passed
2.10 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Parameter Passing via Table
2.11 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Types of System Calls
 Process control: Process control is the system call that is used to
direct the processes.
 end, abort
 load, execute
 create process, terminate process
 get process attributes, set process attributes
 wait for time
 wait event, signal event
 allocate and free memory
 Dump memory if error
 Debugger for determining bugs, single step execution
 Locks for managing access to shared data between processes
2.12 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Types of System Calls
 File management is a system call that is used to handle the files.
 create file, delete file
 open, close file
 read, write, reposition
 get and set file attributes
 Device management is a system call that is used to deal with devices
 request device, release device
 read, write, reposition
 get device attributes, set device attributes
 logically attach or detach devices
2.13 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Types of System Calls (Cont.)
 Information maintenance is used to maintain information
 get time or date, set time or date
 get system data, set system data
 get and set process, file, or device attributes
 Communications is a system call that is used for communication.
 create, delete communication connection
 send, receive messages if message passing model to host name or
process name
 From client to server
 Shared-memory model create and gain access to memory regions
 transfer status information
 attach and detach remote devices
2.14 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Types of System Calls (Cont.)
 Protection
 Control access to resources
 Get and set permissions
 Allow and deny user access
2.15 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 open()
 The open() system call allows you to access a file on a file system. It
allocates resources to the file and provides a handle that the process may
refer to. Many processes can open a file at once or by a single process
only. It's all based on the file system and structure.
 read()
 It is used to obtain data from a file on the file system. It accepts three
arguments in general:
• A file descriptor.
• A buffer to store read data.
• The number of bytes to read from the file.
 The file descriptor of the file to be read could be used to identify it and open
it using open() before reading.
2.16 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 wait()
 In some systems, a process may have to wait for another process to
complete its execution before proceeding. When a parent process makes a
child process, the parent process execution is suspended until the child
process is finished. The wait() system call is used to suspend the parent
process. Once the child process has completed its execution, control is
returned to the parent process.
 write()
 It is used to write data from a user buffer to a device like a file. This system
call is one way for a program to generate data. It takes three arguments in
general:
• A file descriptor.
• A pointer to the buffer in which data is saved.
• The number of bytes to be written from the buffer.
2.17 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 fork()
 It is one of the most common ways to create processes in operating
systems. When a parent process spawns a child process, execution of the
parent process is interrupted until the child process completes. Once the
child process has completed its execution, control is returned to the parent
process.
 close()
 It is used to end file system access. When this system call is invoked, it
signifies that the program no longer requires the file, and the buffers are
flushed, the file information is altered, and the file resources are de-
allocated as a result.
 exec()
 When an executable file replaces an earlier executable file in an already
executing process, this system function is invoked. As a new process is not
built, the old process identification stays, but the new process replaces data,
stack, data, head, etc.
2.18 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 exit()
 The exit() is a system call that is used to end program execution. This call
indicates that the thread execution is complete, which is especially useful in
multi-threaded environments. The operating system reclaims resources
spent by the process following the use of the exit() system function.
2.19 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Examples of Windows and
Unix System Calls
2.20 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Standard C Library Example
 C program invoking printf() library call, which calls write() system call
2.21 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Example: MS-DOS
 Single-tasking
 Shell invoked when system
booted
 Simple method to run
program
 No process created
 Single memory space
 Loads program into memory,
overwriting all but the kernel
 Program exit -> shell
reloaded
(a) At system startup (b) running a program
2.22 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Example: FreeBSD
 Unix variant
 Multitasking
 User login -> invoke user’s choice of
shell
 Shell executes fork() system call to create
process
 Executes exec() to load program into
process
 Shell waits for process to terminate or
continues with user commands
 Process exits with code of 0 – no error or
> 0 – error code
2.23 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Device Drivers
 Operating System takes help from device drivers to handle all I/O
devices.
 A device driver is a computer program that operates or controls a
particular device attached to a computer or automaton.
 A driver provides a software interface to hardware devices, enabling
operating systems and other computer programs to access hardware
functions without knowing precise details about the hardware being
used.
 Device Drivers are important for a computer system to work properly.
Without a device driver, the particular hardware fails to work accordingly,
which means it fails in doing a particular action for which it has been
created.
 Drivers are hardware-dependent and operating-system-specific.
2.24 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 How Device Driver Handles a Request?
 How a device driver handles a request in the operating system is as
follows:
 Suppose a request comes to read a block N. If the driver is idle
when a request arrives, it starts carrying out the request
immediately. Otherwise, if the driver is already busy with some
other request, it places the new request in the queue of pending
requests.
 A device driver performs the following jobs, such as:
• To accept request from the device-independent software above to
it.
• Making sure that the request is executed successfully.
• Interact with the device controller to take and give I/O and perform
required error handling.
2.25 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 The following figure illustrates the interaction between the user, OS, Device
driver, and the devices:
2.26 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Working of Device Drivers
 Generally, a driver communicates with the device through the computer
bus, which connects the device with the computer. Device Drivers
depend upon the Operating System's instruction to access the device
and performing any particular action. After the action, they also show
their reactions by delivering output or message from the hardware device
to the Operating system.
 Device drivers work within the kernel layer of the operating system. The
kernel is the part of the operating system that directly interacts with the
system's physical structure. Instead of accessing a device directly, an
operating system loads the device drivers and calls the specific functions
in the driver software to execute specific tasks on the device. Each driver
contains the device-specific codes required to carry out the actions on
the device.
 Card reader, controller, modem, network card, sound card, printer, video
card, USB devices, RAM, Speakers etc., need Device Drivers to operate.
For example, a printer driver tells the printer which format to print after
getting instructions from OS. Similarly, A sound card driver is there
because the 1's and 0's data of an MP3 file is converted to audio signals,
and you enjoy the music.
2.27 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Types of Device Drivers
 1. Kernel-mode Device Driver
 This Kernel-mode device driver includes some generic hardware that
loads with an operating system as part of the OS. These are BIOS,
motherboard, processor, and some other hardware that are part of
kernel software. These include the minimum system requirement device
drivers for each operating system.
• BIOS: BIOS (basic input/output system) is the most basic computer
driver in existence. It is designed to be the first program that boots when
a PC turns on. The BIOS is stored on memory built into the motherboard
and is designed to boot the hardware connected to the PC, including the
hard drives, video display output, keyboard and mouse.
• Motherboard Drivers: Motherboard drivers are small programs that are
read by either Windows or Linux and allow for basic computer functions
while inside the operating system. These drivers normally include
programs that allow broadband ports, USB ports and I/O ports for the
mouse and keyboard. Depending on the making of the motherboard, the
drivers may also have basic drivers for video and audio support.
2.28 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 2. User-mode Device Driver
 Other than the devices brought by the kernel for working of the system, the
user also brings some devices for use during the using of a system that
devices need device drivers to functions those drivers fall under User mode
device driver. For example, the user needs any plug and play action that
comes under this.
Virtual Device Driver:
 There are also virtual device drivers(VxD), which manage the virtual device.
Sometimes we use the same hardware virtually at that time virtual driver
controls/manages the data flow from the different applications used by
different users to the same hardware.
 Virtual device drivers represent a particular variant of device drivers. They
are used to emulate a hardware device, particularly in virtualization
environments and also in non-virtualization (For example in non virtual, a
virtual network adapter is used with a virtual private network).
2.29 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Operating System Structure
 General-purpose OS is very large program
 Various ways to structure one as follows
2.30 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Simple Structure
 the interfaces and degrees of
functionality in this structure are
clearly defined, programs are
able to access I/O routines, which
may result in unauthorized
access to I/O procedures.
 I.e. MS-DOS – written to provide
the most functionality in the least
space
 Not divided into modules
 Although MS-DOS has some
structure, its interfaces and
levels of functionality are not
well separated
2.31 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 This organizational structure is used by the MS-DOS operating system:
• 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.
2.32 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 Advantages of Simple Structure:
• Because there are only a few interfaces and levels, it is simple to develop.
• Because there are fewer layers between the hardware and the applications,
it offers superior performance.
 Disadvantages of Simple Structure:
• The entire operating system breaks if just one user program malfunctions.
• Since the layers are interconnected, and in communication with one
another, there is no abstraction or data hiding.
• The operating system's operations are accessible to layers, which can result
in data tampering and system failure.
2.33 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
UNIX
 UNIX – limited by hardware functionality, the original UNIX operating
system had limited structuring. The UNIX OS consists of two
separable parts
 Systems programs
 The kernel
 Consists of everything below the system-call interface and
above the physical hardware
 Provides the file system, CPU scheduling, memory
management, and other operating-system functions; a large
number of functions for one level
2.34 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Traditional UNIX System Structure
Beyond simple but not fully layered
2.35 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Layered Approach
 The operating system is
divided into a number of
layers (levels), each built
on top of lower layers.
The bottom layer (layer 0),
is the hardware; the
highest (layer N) is the
user interface.
 With modularity, layers are
selected such that each
uses functions
(operations) and services
of only lower-level layers
2.36 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 Advantages of Layered Structure:
• Work duties are separated since each layer has its own functionality, and
there is some amount of abstraction.
• Debugging is simpler because the lower layers are examined first, followed
by the top layers.
 Disadvantages of Layered Structure:
• Performance is compromised in layered structures due to layering.
• Construction of the layers requires careful design because upper layers only
make use of lower layers' capabilities.
2.37 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Microkernel System Structure
 Moves as much from the kernel into user space
 Mach example of microkernel
 Mac OS X kernel (Darwin) partly based on Mach
 Communication takes place between user modules using message passing
 Each Micro-Kernel is created separately and is kept apart from the others. As a
result, the system is now more trustworthy and secure. If one Micro-Kernel
malfunctions, the remaining operating system is unaffected and continues to
function normally.
 Benefits:
 Easier to extend a microkernel
 Easier to port the operating system to new architectures
 More reliable (less code is running in kernel mode)
 More secure
 Detriments:
 Performance overhead of user space to kernel space communication
 The construction of a system is complicated.
2.38 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Microkernel System Structure
Application
Program
File
System
Device
Driver
Interprocess
Communication
memory
managment
CPU
scheduling
messages
messages
microkernel
hardware
user
mode
kernel
mode
2.39 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Modules
 Most modern operating systems implement loadable kernel modules
 Uses object-oriented approach
 Each core component is separate
 Each talks to the others over known interfaces
 Each is loadable as needed within the kernel
 Overall, similar to layers but with more flexible
 Linux, Solaris, etc
2.40 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Solaris Modular Approach
2.41 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Hybrid Systems
 Most modern operating systems actually not one pure model
 Hybrid combines multiple approaches to address performance, security,
usability needs
 Linux and Solaris kernels in kernel address space, so monolithic, plus
modular for dynamic loading of functionality
 Windows mostly monolithic, plus microkernel for different subsystem
personalities
 Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming
environment
 Below is kernel consisting of Mach microkernel and BSD Unix parts,
plus I/O kit and dynamically loadable modules (called kernel
extensions)
2.42 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Mac OS X Structure
graphical user interface
Aqua
application environments and services
kernel environment
Java Cocoa Quicktime BSD
Mach
I/O kit kernel extensions
BSD
2.43 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
 The monolithic operating system controls all aspects of the operating system's
operation, including file management, memory management, device
management, and operational operations.
 The core of an operating system for computers is called the kernel (OS). All
other System components are provided with fundamental services by the
kernel.
 The operating system and the hardware use it as their main interface. When an
operating system is built into a single piece of hardware, such as a keyboard or
mouse, the kernel can directly access all of its resources.
 The monolithic operating system is often referred to as the monolithic
kernel. Multiple programming techniques such as batch processing and time-
sharing increase a processor's usability
 This is an old operating system that was used in banks to carry out simple
tasks like batch processing and time-sharing, which allows numerous users at
different terminals to access the Operating System.
Monolithic Structure
2.44 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
2.45 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
iOS
 Apple mobile OS for iPhone, iPad
 Structured on Mac OS X, added functionality
 Does not run OS X applications natively
 Also runs on different CPU architecture
(ARM vs. Intel)
 Cocoa Touch Objective-C API for
developing apps
 Media services layer for graphics, audio,
video
 Core services provides cloud computing,
databases
 Core operating system, based on Mac OS X
kernel
2.46 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Android
 Developed by Open Handset Alliance (mostly Google)
 Open Source
 Similar stack to IOS
 Based on Linux kernel but modified
 Provides process, memory, device-driver management
 Adds power management
 Runtime environment includes core set of libraries and Dalvik virtual
machine
 Apps developed in Java plus Android API
 Java class files compiled to Java bytecode then translated to
executable than runs in Dalvik VM
 Libraries include frameworks for web browser (webkit), database
(SQLite), multimedia, smaller libc
2.47 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Android Architecture
Applications
Application Framework
Android runtime
Core Libraries
Dalvik
virtual machine
Libraries
Linux kernel
SQLite openGL
surface
manager
webkit libc
media
framework

More Related Content

PPTX
Current therapies in management of neuropathic pain
PPT
Edição do aniversário de 40 anos da escola
PPTX
O ensino de história no Brasil está associado à constituição de identidade na...
PPT
System Calls.ppt
PPT
operating Systems Structures and functions
PPT
MODULE 2.ppt
PDF
Operation system structure
PPTX
Current therapies in management of neuropathic pain
Edição do aniversário de 40 anos da escola
O ensino de história no Brasil está associado à constituição de identidade na...
System Calls.ppt
operating Systems Structures and functions
MODULE 2.ppt
Operation system structure

Similar to W5 system call, DD, OS structure.ppt (20)

PPTX
Operating System Chapter Two Process Related Concepts
PPTX
Operating system structures
PPT
PPT
ch2.ppt
PPT
ch2.ppt
PPT
PPT
Operating-System Structures
PPT
PPT
operating system structures by silberschastz
PDF
Operating System - Unit I - Operating System Structures
PPT
operating system introduction to os1.ppt
PPT
chapter 2 operating systems galvin slides
PPT
Operating System task and sub task system call ch2 system call.ppt
PPT
process and threads in operating systems
PPT
Computer Operating Systems Structure Management Chapter 2
PPT
chapter 2 name:- operating System Structures
PPT
Operating System- Structures of Operating System
PPTX
Unit 1 ppt
Operating System Chapter Two Process Related Concepts
Operating system structures
ch2.ppt
ch2.ppt
Operating-System Structures
operating system structures by silberschastz
Operating System - Unit I - Operating System Structures
operating system introduction to os1.ppt
chapter 2 operating systems galvin slides
Operating System task and sub task system call ch2 system call.ppt
process and threads in operating systems
Computer Operating Systems Structure Management Chapter 2
chapter 2 name:- operating System Structures
Operating System- Structures of Operating System
Unit 1 ppt
Ad

Recently uploaded (20)

PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
master seminar digital applications in india
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Lesson notes of climatology university.
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
01-Introduction-to-Information-Management.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Presentation on HIE in infants and its manifestations
2.FourierTransform-ShortQuestionswithAnswers.pdf
Final Presentation General Medicine 03-08-2024.pptx
Pharma ospi slides which help in ospi learning
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
master seminar digital applications in india
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
RMMM.pdf make it easy to upload and study
Lesson notes of climatology university.
VCE English Exam - Section C Student Revision Booklet
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Complications of Minimal Access Surgery at WLH
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
01-Introduction-to-Information-Management.pdf
Anesthesia in Laparoscopic Surgery in India
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Presentation on HIE in infants and its manifestations
Ad

W5 system call, DD, OS structure.ppt

  • 1. 2.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Operating system Week 5 BSIT 4th
  • 2. 2.2 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition System Calls  A system call is a function that a user program uses to ask the operating system for a particular service. User programmers can communicate with the operating system to request its services using the interface that is created by a system call.  Programming interface to the services provided by the OS  Typically written in a high-level language (C or C++)  Mostly accessed by programs via a high-level Application Programming Interface (API) rather than direct system call use  Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM)  Why use APIs rather than system calls?
  • 3. 2.3 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Example of System Calls  System call sequence to copy the contents of one file to another file
  • 4. 2.4 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Example of Standard API
  • 5. 2.5 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  Why do you need system calls in Operating System?  There are various situations where you must require system calls in the operating system. Following of the situations are as follows: 1. It is must require when a file system wants to create or delete a file. 2. Network connections require the system calls to sending and receiving data packets. 3. If you want to read or write a file, you need to system calls. 4. If you want to access hardware devices, including a printer, scanner, you need a system call. 5. System calls are used to create and manage new processes.
  • 6. 2.6 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition System Call Implementation  Typically, a number associated with each system call  System-call interface maintains a table indexed according to these numbers  The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values  The caller need know nothing about how the system call is implemented  Just needs to obey API and understand what OS will do as a result call  Most details of OS interface hidden from programmer by API  Managed by run-time support library (set of functions built into libraries included with compiler)
  • 7. 2.7 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition How System Calls Work  The Applications run in an area of memory known as user space.  A system call connects to the operating system's kernel, which executes in kernel space.  When an application creates a system call, it must first obtain permission from the kernel. It achieves this using an interrupt request, which pauses the current process and transfers control to the kernel.  If the request is permitted, the kernel performs the requested action, like creating or deleting a file. As input, the application receives the kernel's output. The application resumes the procedure after the input is received. When the operation is finished, the kernel returns the results to the application and then moves data from kernel space to user space in memory.
  • 8. 2.8 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition API – System Call – OS Relationship
  • 9. 2.9 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition System Call Parameter Passing  Often, more information is required than simply identity of desired system call  Exact type and amount of information vary according to OS and call  Three general methods used to pass parameters to the OS  Simplest: pass the parameters in registers  In some cases, may be more parameters than registers  Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register  This approach taken by Linux and Solaris  Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system  Block and stack methods do not limit the number or length of parameters being passed
  • 10. 2.10 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Parameter Passing via Table
  • 11. 2.11 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Types of System Calls  Process control: Process control is the system call that is used to direct the processes.  end, abort  load, execute  create process, terminate process  get process attributes, set process attributes  wait for time  wait event, signal event  allocate and free memory  Dump memory if error  Debugger for determining bugs, single step execution  Locks for managing access to shared data between processes
  • 12. 2.12 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Types of System Calls  File management is a system call that is used to handle the files.  create file, delete file  open, close file  read, write, reposition  get and set file attributes  Device management is a system call that is used to deal with devices  request device, release device  read, write, reposition  get device attributes, set device attributes  logically attach or detach devices
  • 13. 2.13 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Types of System Calls (Cont.)  Information maintenance is used to maintain information  get time or date, set time or date  get system data, set system data  get and set process, file, or device attributes  Communications is a system call that is used for communication.  create, delete communication connection  send, receive messages if message passing model to host name or process name  From client to server  Shared-memory model create and gain access to memory regions  transfer status information  attach and detach remote devices
  • 14. 2.14 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Types of System Calls (Cont.)  Protection  Control access to resources  Get and set permissions  Allow and deny user access
  • 15. 2.15 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  open()  The open() system call allows you to access a file on a file system. It allocates resources to the file and provides a handle that the process may refer to. Many processes can open a file at once or by a single process only. It's all based on the file system and structure.  read()  It is used to obtain data from a file on the file system. It accepts three arguments in general: • A file descriptor. • A buffer to store read data. • The number of bytes to read from the file.  The file descriptor of the file to be read could be used to identify it and open it using open() before reading.
  • 16. 2.16 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  wait()  In some systems, a process may have to wait for another process to complete its execution before proceeding. When a parent process makes a child process, the parent process execution is suspended until the child process is finished. The wait() system call is used to suspend the parent process. Once the child process has completed its execution, control is returned to the parent process.  write()  It is used to write data from a user buffer to a device like a file. This system call is one way for a program to generate data. It takes three arguments in general: • A file descriptor. • A pointer to the buffer in which data is saved. • The number of bytes to be written from the buffer.
  • 17. 2.17 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  fork()  It is one of the most common ways to create processes in operating systems. When a parent process spawns a child process, execution of the parent process is interrupted until the child process completes. Once the child process has completed its execution, control is returned to the parent process.  close()  It is used to end file system access. When this system call is invoked, it signifies that the program no longer requires the file, and the buffers are flushed, the file information is altered, and the file resources are de- allocated as a result.  exec()  When an executable file replaces an earlier executable file in an already executing process, this system function is invoked. As a new process is not built, the old process identification stays, but the new process replaces data, stack, data, head, etc.
  • 18. 2.18 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  exit()  The exit() is a system call that is used to end program execution. This call indicates that the thread execution is complete, which is especially useful in multi-threaded environments. The operating system reclaims resources spent by the process following the use of the exit() system function.
  • 19. 2.19 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Examples of Windows and Unix System Calls
  • 20. 2.20 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Standard C Library Example  C program invoking printf() library call, which calls write() system call
  • 21. 2.21 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Example: MS-DOS  Single-tasking  Shell invoked when system booted  Simple method to run program  No process created  Single memory space  Loads program into memory, overwriting all but the kernel  Program exit -> shell reloaded (a) At system startup (b) running a program
  • 22. 2.22 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Example: FreeBSD  Unix variant  Multitasking  User login -> invoke user’s choice of shell  Shell executes fork() system call to create process  Executes exec() to load program into process  Shell waits for process to terminate or continues with user commands  Process exits with code of 0 – no error or > 0 – error code
  • 23. 2.23 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Device Drivers  Operating System takes help from device drivers to handle all I/O devices.  A device driver is a computer program that operates or controls a particular device attached to a computer or automaton.  A driver provides a software interface to hardware devices, enabling operating systems and other computer programs to access hardware functions without knowing precise details about the hardware being used.  Device Drivers are important for a computer system to work properly. Without a device driver, the particular hardware fails to work accordingly, which means it fails in doing a particular action for which it has been created.  Drivers are hardware-dependent and operating-system-specific.
  • 24. 2.24 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  How Device Driver Handles a Request?  How a device driver handles a request in the operating system is as follows:  Suppose a request comes to read a block N. If the driver is idle when a request arrives, it starts carrying out the request immediately. Otherwise, if the driver is already busy with some other request, it places the new request in the queue of pending requests.  A device driver performs the following jobs, such as: • To accept request from the device-independent software above to it. • Making sure that the request is executed successfully. • Interact with the device controller to take and give I/O and perform required error handling.
  • 25. 2.25 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  The following figure illustrates the interaction between the user, OS, Device driver, and the devices:
  • 26. 2.26 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Working of Device Drivers  Generally, a driver communicates with the device through the computer bus, which connects the device with the computer. Device Drivers depend upon the Operating System's instruction to access the device and performing any particular action. After the action, they also show their reactions by delivering output or message from the hardware device to the Operating system.  Device drivers work within the kernel layer of the operating system. The kernel is the part of the operating system that directly interacts with the system's physical structure. Instead of accessing a device directly, an operating system loads the device drivers and calls the specific functions in the driver software to execute specific tasks on the device. Each driver contains the device-specific codes required to carry out the actions on the device.  Card reader, controller, modem, network card, sound card, printer, video card, USB devices, RAM, Speakers etc., need Device Drivers to operate. For example, a printer driver tells the printer which format to print after getting instructions from OS. Similarly, A sound card driver is there because the 1's and 0's data of an MP3 file is converted to audio signals, and you enjoy the music.
  • 27. 2.27 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Types of Device Drivers  1. Kernel-mode Device Driver  This Kernel-mode device driver includes some generic hardware that loads with an operating system as part of the OS. These are BIOS, motherboard, processor, and some other hardware that are part of kernel software. These include the minimum system requirement device drivers for each operating system. • BIOS: BIOS (basic input/output system) is the most basic computer driver in existence. It is designed to be the first program that boots when a PC turns on. The BIOS is stored on memory built into the motherboard and is designed to boot the hardware connected to the PC, including the hard drives, video display output, keyboard and mouse. • Motherboard Drivers: Motherboard drivers are small programs that are read by either Windows or Linux and allow for basic computer functions while inside the operating system. These drivers normally include programs that allow broadband ports, USB ports and I/O ports for the mouse and keyboard. Depending on the making of the motherboard, the drivers may also have basic drivers for video and audio support.
  • 28. 2.28 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  2. User-mode Device Driver  Other than the devices brought by the kernel for working of the system, the user also brings some devices for use during the using of a system that devices need device drivers to functions those drivers fall under User mode device driver. For example, the user needs any plug and play action that comes under this. Virtual Device Driver:  There are also virtual device drivers(VxD), which manage the virtual device. Sometimes we use the same hardware virtually at that time virtual driver controls/manages the data flow from the different applications used by different users to the same hardware.  Virtual device drivers represent a particular variant of device drivers. They are used to emulate a hardware device, particularly in virtualization environments and also in non-virtualization (For example in non virtual, a virtual network adapter is used with a virtual private network).
  • 29. 2.29 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Operating System Structure  General-purpose OS is very large program  Various ways to structure one as follows
  • 30. 2.30 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Simple Structure  the interfaces and degrees of functionality in this structure are clearly defined, programs are able to access I/O routines, which may result in unauthorized access to I/O procedures.  I.e. MS-DOS – written to provide the most functionality in the least space  Not divided into modules  Although MS-DOS has some structure, its interfaces and levels of functionality are not well separated
  • 31. 2.31 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  This organizational structure is used by the MS-DOS operating system: • 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.
  • 32. 2.32 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  Advantages of Simple Structure: • Because there are only a few interfaces and levels, it is simple to develop. • Because there are fewer layers between the hardware and the applications, it offers superior performance.  Disadvantages of Simple Structure: • The entire operating system breaks if just one user program malfunctions. • Since the layers are interconnected, and in communication with one another, there is no abstraction or data hiding. • The operating system's operations are accessible to layers, which can result in data tampering and system failure.
  • 33. 2.33 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition UNIX  UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring. The UNIX OS consists of two separable parts  Systems programs  The kernel  Consists of everything below the system-call interface and above the physical hardware  Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level
  • 34. 2.34 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Traditional UNIX System Structure Beyond simple but not fully layered
  • 35. 2.35 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Layered Approach  The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface.  With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers
  • 36. 2.36 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  Advantages of Layered Structure: • Work duties are separated since each layer has its own functionality, and there is some amount of abstraction. • Debugging is simpler because the lower layers are examined first, followed by the top layers.  Disadvantages of Layered Structure: • Performance is compromised in layered structures due to layering. • Construction of the layers requires careful design because upper layers only make use of lower layers' capabilities.
  • 37. 2.37 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Microkernel System Structure  Moves as much from the kernel into user space  Mach example of microkernel  Mac OS X kernel (Darwin) partly based on Mach  Communication takes place between user modules using message passing  Each Micro-Kernel is created separately and is kept apart from the others. As a result, the system is now more trustworthy and secure. If one Micro-Kernel malfunctions, the remaining operating system is unaffected and continues to function normally.  Benefits:  Easier to extend a microkernel  Easier to port the operating system to new architectures  More reliable (less code is running in kernel mode)  More secure  Detriments:  Performance overhead of user space to kernel space communication  The construction of a system is complicated.
  • 38. 2.38 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Microkernel System Structure Application Program File System Device Driver Interprocess Communication memory managment CPU scheduling messages messages microkernel hardware user mode kernel mode
  • 39. 2.39 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Modules  Most modern operating systems implement loadable kernel modules  Uses object-oriented approach  Each core component is separate  Each talks to the others over known interfaces  Each is loadable as needed within the kernel  Overall, similar to layers but with more flexible  Linux, Solaris, etc
  • 40. 2.40 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Solaris Modular Approach
  • 41. 2.41 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Hybrid Systems  Most modern operating systems actually not one pure model  Hybrid combines multiple approaches to address performance, security, usability needs  Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic loading of functionality  Windows mostly monolithic, plus microkernel for different subsystem personalities  Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming environment  Below is kernel consisting of Mach microkernel and BSD Unix parts, plus I/O kit and dynamically loadable modules (called kernel extensions)
  • 42. 2.42 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Mac OS X Structure graphical user interface Aqua application environments and services kernel environment Java Cocoa Quicktime BSD Mach I/O kit kernel extensions BSD
  • 43. 2.43 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition  The monolithic operating system controls all aspects of the operating system's operation, including file management, memory management, device management, and operational operations.  The core of an operating system for computers is called the kernel (OS). All other System components are provided with fundamental services by the kernel.  The operating system and the hardware use it as their main interface. When an operating system is built into a single piece of hardware, such as a keyboard or mouse, the kernel can directly access all of its resources.  The monolithic operating system is often referred to as the monolithic kernel. Multiple programming techniques such as batch processing and time- sharing increase a processor's usability  This is an old operating system that was used in banks to carry out simple tasks like batch processing and time-sharing, which allows numerous users at different terminals to access the Operating System. Monolithic Structure
  • 44. 2.44 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition
  • 45. 2.45 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition iOS  Apple mobile OS for iPhone, iPad  Structured on Mac OS X, added functionality  Does not run OS X applications natively  Also runs on different CPU architecture (ARM vs. Intel)  Cocoa Touch Objective-C API for developing apps  Media services layer for graphics, audio, video  Core services provides cloud computing, databases  Core operating system, based on Mac OS X kernel
  • 46. 2.46 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Android  Developed by Open Handset Alliance (mostly Google)  Open Source  Similar stack to IOS  Based on Linux kernel but modified  Provides process, memory, device-driver management  Adds power management  Runtime environment includes core set of libraries and Dalvik virtual machine  Apps developed in Java plus Android API  Java class files compiled to Java bytecode then translated to executable than runs in Dalvik VM  Libraries include frameworks for web browser (webkit), database (SQLite), multimedia, smaller libc
  • 47. 2.47 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Android Architecture Applications Application Framework Android runtime Core Libraries Dalvik virtual machine Libraries Linux kernel SQLite openGL surface manager webkit libc media framework