0% found this document useful (0 votes)
10 views34 pages

Chapter2-OS Services

Chapter 2 of 'Operating System Concepts' discusses the various services provided by operating systems, including user interfaces, program execution, I/O operations, and error detection. It explains the role of system calls in accessing these services and outlines the design and implementation factors for creating an operating system. Additionally, the chapter covers debugging, performance tuning, and the importance of separating policy from mechanism in OS design.

Uploaded by

farwinoor9
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)
10 views34 pages

Chapter2-OS Services

Chapter 2 of 'Operating System Concepts' discusses the various services provided by operating systems, including user interfaces, program execution, I/O operations, and error detection. It explains the role of system calls in accessing these services and outlines the design and implementation factors for creating an operating system. Additionally, the chapter covers debugging, performance tuning, and the importance of separating policy from mechanism in OS design.

Uploaded by

farwinoor9
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
You are on page 1/ 34

Chapter 2: Operating-System

Services

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Objectives

 Identify services provided by an operating system


 Illustrate how system calls are used to provide operating system
services.
 Define the factors required to design a new OS
 How to troubleshoot any operating system?

Operating System Concepts – 10th Edition 2.2 Silberschatz, Galvin and Gagne ©2018
Chapter 2: Outline

 Operating System Services


 System Calls
• Types of System Calls
• Standard C Example
 Why Applications are Operating System Specific
 OS Design and Implementation
• Policy and Mechanism
 Building and Booting an Operating System
 Operating System Debugging
• Performance tuning
• Tracing

Operating System Concepts – 10th Edition 2.3 Silberschatz, Galvin and Gagne ©2018
Operating System Services

Operating System Concepts – 10th Edition 2.4 Silberschatz, Galvin and Gagne ©2018
Operating System Services

Operating System Concepts – 10th Edition 2.5 Silberschatz, Galvin and Gagne ©2018
Operating System Services
 Operating systems provide an environment for the execution of
programs and services to programs and users
 One set of operating-system services provides functions that are
helpful to the user:
• User interface - Almost all operating systems have a user
interface (UI).
 Varies between Command-Line (CLI), Graphics User
Interface (GUI), touch-screen
• Program execution - The system must be able to load a program
into memory and to run that program, end execution, either
normally or abnormally (indicating error)
• I/O operations - A running program may require I/O, which may
involve a file or an I/O device
• File-system manipulation - The file system is of particular
interest. Programs need to read and write files and directories,
create and delete them, search them, list file Information,
permission management.

Operating System Concepts – 10th Edition 2.6 Silberschatz, Galvin and Gagne ©2018
Operating System Services (Cont.)

 Communications – Processes may exchange information, on the


same computer or between computers over a network
• Communications may be via shared memory or through message
passing (packets moved by the OS)
• Resource allocation
• Resource allocation to concurrently running jobs
• Resources such as CPU cycles, main memory, file storage etc.
 Accounting
Track usage of computer resources
For billing or simply for accumulating usage statistics

Operating System Concepts – 10th Edition 2.7 Silberschatz, Galvin and Gagne ©2018
Operating System Services (Cont.)
 Error detection – OS needs to be constantly aware of possible errors
• May occur in the CPU and memory hardware, in I/O devices, in
user program
• For each type of error, OS should take the appropriate action to
ensure correct and consistent computing
• Debugging facilities can greatly enhance the user’s and
programmer’s abilities to use the system efficiently
 Protection and security
– Protect access to system resources is controlled
– Security from the outsiders, e.g., user authentication

Operating System Concepts – 10th Edition 2.8 Silberschatz, Galvin and Gagne ©2018
System Services (Cont.)
 Background Services
• Launch at boot time
Some for system startup, then terminate

 Some from system boot to shutdown

• Provide facilities like disk checking, process scheduling, error


logging, printing
• Run in user context not kernel context
• Known as services, subsystems, daemons
 Application programs
• Don’t pertain to system
• Run by users
• Not typically considered part of OS
• Launched by command line, mouse click, finger poke

Operating System Concepts – 10th Edition 2.9 Silberschatz, Galvin and Gagne ©2018
Overview of Services in typical
Windows O.S.

Operating System Concepts – 10th Edition 2.10 Silberschatz, Galvin and Gagne ©2018
System Calls

Operating System Concepts – 10th Edition 2.11 Silberschatz, Galvin and Gagne ©2018
System Calls

 Programmatic way in which computer program requests a service from


OS.
 User Mode is safer way to access resources and its happening
through calls. This context-switching is handled by OS through system
calls.
 Typically these calls are written as routines 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.
This interface is also known as SCI ( System call Interface)
 Three most common APIs are:
• Win32 API for Windows
• Portable OS interface(POSIX) API for POSIX-based systems
(including virtually all versions of UNIX, Linux, and Mac OS X)
• Java API for the Java virtual machine (JVM)

Operating System Concepts – 10th Edition 2.12 Silberschatz, Galvin and Gagne ©2018
Example of System Calls
 System call sequence to copy the contents of one file to another
file

Operating System Concepts – 10th Edition 2.13 Silberschatz, Galvin and Gagne ©2018
Example of Standard API

Operating System Concepts – 10th Edition 2.14 Silberschatz, Galvin and Gagne ©2018
System Call Implementation
 Typically, 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
 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)

Operating System Concepts – 10th Edition 2.15 Silberschatz, Galvin and Gagne ©2018
API – System Call – OS Relationship

Operating System Concepts – 10th Edition 2.16 Silberschatz, Galvin and Gagne ©2018
Standard C Library Example
 C program invoking printf() library call, which calls write() system call

Operating System Concepts – 10th Edition 2.17 Silberschatz, Galvin and Gagne ©2018
Types of System Calls

 Process control
• create process, terminate process
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Debugger for determining bugs, single-step execution
• Locks for managing access to shared data between processes

Operating System Concepts – 10th Edition 2.18 Silberschatz, Galvin and Gagne ©2018
Types of System Calls (Cont.)
 File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
 Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices

Operating System Concepts – 10th Edition 2.19 Silberschatz, Galvin and Gagne ©2018
Types of System Calls (Cont.)
 Information maintenance ( Metadata )
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
 Communications (IPC)
• 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

Operating System Concepts – 10th Edition 2.20 Silberschatz, Galvin and Gagne ©2018
Types of System Calls (Cont.)
 Protection & Security
• Control access to resources
• Get and set permissions
• Allow and deny user access

Operating System Concepts – 10th Edition 2.21 Silberschatz, Galvin and Gagne ©2018
Examples of Windows and Unix System Calls

Operating System Concepts – 10th Edition 2.22 Silberschatz, Galvin and Gagne ©2018
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
 Application Binary Interface (ABI) is architecture equivalent of API,
defines how different components of binary code can interface for a
given operating system on a given architecture, CPU, etc.

Operating System Concepts – 10th Edition 2.23 Silberschatz, Galvin and Gagne ©2018
Operating System Design &
Implementation

Operating System Concepts – 10th Edition 2.24 Silberschatz, Galvin and Gagne ©2018
Design and Implementation

 Design and Implementation of OS is not “solvable”, but some


approaches have proven successful
 Internal structure of different Operating Systems can vary widely
 Start the design by defining goals and specifications
 Affected by choice of hardware, type of system
 User goals and System goals
• User goals – operating system should be convenient to use,
easy to learn, reliable, safe, and fast
• System goals – operating system should be easy to design,
implement, and maintain, as well as flexible, reliable, error-free,
and efficient
 Specifying and designing an OS is highly creative task of software
engineering

Operating System Concepts – 10th Edition 2.25 Silberschatz, Galvin and Gagne ©2018
Policy and Mechanism
 Policy: What needs to be done?
• Example: Interrupt after every 100 seconds
 Mechanism: How to do something?
• Example: timer
 Important principle: separate policy from mechanism
 The separation of policy from mechanism is a very
important principle, it allows maximum flexibility if policy
decisions are to be changed later.
• Example: change 100 to 200

Operating System Concepts – 10th Edition 2.26 Silberschatz, Galvin and Gagne ©2018
Implementation
 Much variation
• Early OSes in assembly language
• Then system programming languages like Algol, PL/1
• Now C, C++
 Actually usually a mix of languages
• Lowest levels in assembly
• Main body in C
• Systems programs in C, C++, scripting languages like PERL,
Python, shell scripts
 More high-level language easier to port to other hardware
• But slower

Operating System Concepts – 10th Edition 2.27 Silberschatz, Galvin and Gagne ©2018
Building and Booting an Operating System

 Operating systems generally designed to run on a class of systems


with variety of peripherals
 Commonly, operating system already installed on purchased
computer
• But can build and install some other operating systems
• If generating an operating system from scratch
 Write the operating system source code
 Configure the operating system for the system on which it will
run
 Compile the operating system
 Install the operating system
 Boot the computer and its new operating system

Operating System Concepts – 10th Edition 2.28 Silberschatz, Galvin and Gagne ©2018
System Boot-Recap
 When power initialized on system, execution starts at a fixed memory
location
 Operating system must be made available to hardware so hardware
can start it
• Small piece of code – bootstrap loader, BIOS, stored in ROM or
EEPROM locates the kernel, loads it into memory, and starts it
 Common bootstrap loader, GRUB, allows selection of kernel from
multiple disks, versions, kernel options ( Linux Distros)
 Kernel loads and system is then running
 Boot loaders frequently allow various boot states, such as single user
mode

Operating System Concepts – 10th Edition 2.29 Silberschatz, Galvin and Gagne ©2018
Operating System Debugging

Operating System Concepts – 10th Edition 2.30 Silberschatz, Galvin and Gagne ©2018
Operating-System Debugging

 Debugging is finding and fixing errors, or bugs


 OS generate log files containing error information
 Failure of an application can generate core dump file capturing
memory of the process ( In Unix Like systems)
 Operating system failure can generate crash dump file containing
snapshot of process’s state at the time of crash. ( In windows)

Kernighan’s Law: “Debugging is twice as hard as writing the code in


the first place.”

Operating System Concepts – 10th Edition 2.31 Silberschatz, Galvin and Gagne ©2018
Performance Tuning
 Beyond crashes, performance tuning can optimize system
performance
• Profiling is periodic sampling of instruction pointer to look for
statistical trends
 Improve performance by removing bottlenecks
 OS must provide means of computing and displaying measures of
system behavior
 For example, Windows Task Manager

Operating System Concepts – 10th Edition 2.32 Silberschatz, Galvin and Gagne ©2018
Tracing

 Collects data for a specific event, such as steps involved


in a system call invocation
 Sometimes using trace listings of activities, recorded for
analysis
 Tools include
• strace – trace system calls invoked by a process
• gdb – source-level debugger
• perf – a collection of Linux performance tools
• tcpdump – collects network packets

Operating System Concepts – 10th Edition 2.33 Silberschatz, Galvin and Gagne ©2018
End of Chapter 2

Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018

You might also like