0% found this document useful (0 votes)
29 views40 pages

6-ch2 Part2

The document outlines the topics to be covered in an Operating Systems course, including operating system services, system calls, linkers and loaders, and why applications are operating system specific. It provides examples of the Arduino platform and standard C library to illustrate concepts. System services provided by operating systems are divided into file manipulation, status information, programming language support, program loading and execution, communications, background services, and application programs. Linkers combine object files into executable files and loaders bring executable files into memory to be executed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
29 views40 pages

6-ch2 Part2

The document outlines the topics to be covered in an Operating Systems course, including operating system services, system calls, linkers and loaders, and why applications are operating system specific. It provides examples of the Arduino platform and standard C library to illustrate concepts. System services provided by operating systems are divided into file manipulation, status information, programming language support, program loading and execution, communications, background services, and application programs. Linkers combine object files into executable files and loaders bring executable files into memory to be executed.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 40

Year: 2023-2024

Fall Semester

Operating Systems

Dr. Wafaa Samy

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.1 Modified by Dr. Wafaa Samy
Chapter 2: Operating-System
Services (Part 2)

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 Modified by Dr. Wafaa Samy
Outline

 Operating System Services


 User and Operating System-Interface
 System Calls
 System Services
 Linkers and Loaders
 Why Applications are Operating System Specific
 Design and Implementation
 Operating System Structure
 Building and Booting an Operating System
 Operating System Debugging

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.3 Modified by Dr. Wafaa Samy
Standard C Library Example
 The standard C library provides
a portion of the system-call
interface for many versions of
UNIX and Linux.
 For example, let’s assume a C
program invokes the printf()
statement.
 The C library intercepts this call
and invokes the necessary
system call (or calls) in the
operating system—in this
instance, the write() system
call.
 The C library takes the value
returned by write() and passes C program invoking printf() library call,
it back to the user program. which calls write() system call.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.4 Modified by Dr. Wafaa Samy
Example: Arduino
 A single-tasking system.
 No operating system.
 Programs (sketch) loaded via USB
into flash memory.
 Single memory space.
 Boot loader loads program.
 Program exit -> shell reloaded.
At system startup running a program

 The Arduino is a simple hardware platform consisting of a microcontroller along


with input sensors that respond to a variety of events, such as changes to light,
temperature, and barometric pressure, etc.
 To write a program for the Arduino, we first write the program on a PC and then
upload the compiled program (known as a sketch) from the PC to the Arduino’s
flash memory via a USB connection.
 The standard Arduino platform does not provide an operating system; instead, a
small piece of software known as a boot loader loads the sketch into a specific
region in the Arduino’s memory. Once the sketch has been loaded, it begins
running, waiting for the events that it is programmed to respond to.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.5 Modified by Dr. Wafaa Samy
Example: Arduino (Cont.)
 For example, if the Arduino’s temperature sensor detects that the
temperature has exceeded a certain threshold, the sketch may
have the Arduino start the motor for a fan.

 An Arduino is considered a single-tasking system, as only one


sketch can be present in memory at a time; if another sketch is
loaded, it replaces the existing sketch.

 Furthermore, the Arduino provides no user interface beyond


hardware input sensors.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.6 Modified by Dr. Wafaa Samy
System Services

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.7 Modified by Dr. Wafaa Samy
System Services
 System programs (or system utilities) provide a convenient
environment for program development and execution. They can be
divided into:
1. File manipulation.
2. Status information sometimes stored in a file.
3. Programming language support.
4. Program loading and execution.
5. Communications.
6. Background services.
7. Application programs.

 Most users’ view of the operation system is defined by system


programs, not the actual system calls.
 System programs provide a convenient environment for program
development and execution:
• Some of them are simply user interfaces to system calls.
• Others are considerably more complex.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.8 Modified by Dr. Wafaa Samy
System Services (Cont.)
1. File management - These programs create, delete, copy, rename, print,
dump, list, and generally manipulate files and directories.
2. Status information:
• Some programs ask the system for info - date, time, amount of available
memory, disk space, number of users, or similar status information.
• Others are more complex, providing detailed performance, logging, and
debugging information.
• Typically, these programs format and print the output to the terminal or
other output devices or files or display it in a window of the GUI.
• Some systems implement a registry - used to store and retrieve
configuration information.
3. File modification:
• Text editors to create and modify files stored on disk or other storage
devices.
• Special commands to search contents of files or perform transformations of
the text.
4. Programming-language support - Compilers, assemblers, debuggers
and interpreters for common programming languages (such as C, C++,
Java, and Python) are often sometimes provided.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.9 Modified by Dr. Wafaa Samy
System Services (Cont.)
5. Program loading and execution - Absolute loaders, relocatable
loaders, linkage editors, and overlay-loaders, debugging systems for
higher-level and machine language. Once a program is assembled or
compiled, it must be loaded into memory to be executed.
6. Communications - Provide the mechanism for creating virtual connections
among processes, users, and computer systems: Allow users to send
messages to one another’s screens, browse web pages, send e-mail
messages, log in remotely, transfer files from one machine to another.
7. Background Services:
• Known as services, subsystems, daemons.
• Launch at boot time:
 Some for system startup, then terminate.
 Some from system boot to shutdown.
• Provide facilities like disk checking, process scheduling that start
processes according to a specified schedule, error logging (system
error monitoring services), and printing servers.
• Run in user context not kernel context.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.10 Modified by Dr. Wafaa Samy
System Services (Cont.)
8. Application programs: include web browsers, word processors and text
formatters, spreadsheets, database systems, compilers, plotting and
statistical-analysis packages, and games.
• 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


Silberschatz, Galvin and Gagne ©2018 2.11 Modified by Dr. Wafaa Samy
Linkers and Loaders

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.12 Modified by Dr. Wafaa Samy
Linkers and Loaders
 Source code compiled into object files designed to be loaded into any
physical memory location – a format known as relocatable object file.
 Linker combines these relocatable object files into single binary executable
file.
• Also brings in libraries: During the linking phase, other object files or
libraries may be included as well.
 Program resides on secondary storage as binary executable.
 Must be brought into memory by loader to be executed:
• Relocation assigns final addresses to program parts and adjusts code
and data in program to match those addresses.
 Modern general purpose systems don’t link libraries into executables:
• Rather, dynamically linked libraries (in Windows, DLLs) are loaded
as needed, shared by all that use the same version of that same library
(loaded once).
 Object, executable files have standard formats, so operating system knows
how to load and start them.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.13 Modified by Dr. Wafaa Samy
The Role of the Linker and Loader
• When a program name is entered
on the command line on UNIX
systems—for example, ./main.
• The shell first creates a new
process to run the program
using the fork() system call.
• The shell then invokes the
loader with the exec() system
call, passing exec() the name of
the executable file.
• The loader then loads the
specified program into memory
using the address space of the
newly created process.
• (When a GUI interface is used,
double-clicking on the icon
associated with the executable
file invokes the loader using a
similar mechanism).
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.14 Modified by Dr. Wafaa Samy
Why Applications are Operating System Specific

 Apps compiled on one system usually not executable on other


OSes.
 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.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.15 Modified by Dr. Wafaa Samy
Building and Booting an Operating System

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.16 Modified by Dr. Wafaa Samy
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 (or obtain
previously written source code).
 Configure the OS for the system on which it will run.
Configuring the system involves specifying which features will
be included.
 Compile the operating system.
 Install the operating system.
 Boot the computer and its new operating system.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.17 Modified by Dr. Wafaa Samy
Building and Booting Linux
 Download Linux source code (http://www.kernel.org).
 Configure kernel via “make menuconfig”.
 Compile the kernel using “make”.
• Produces vmlinuz, the kernel image.
• Compile kernel modules via “make modules”.
• Install kernel modules into vmlinuz via “make
modules_install”.
• Install new kernel on the system via “make install”.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.18 Modified by Dr. Wafaa Samy
System Boot
 The process of starting a computer by loading the kernel is known as
booting the system. But how the kernel is loaded?
 On most systems, the boot process proceeds as follows:
• Small piece of code – bootstrap loader, BIOS, stored in ROM or
EEPROM locates the kernel, loads it into memory, and starts it.
 Some computer systems use a multistage boot process: Sometimes two-
step process where boot block at fixed location loaded by ROM code,
which loads bootstrap loader from disk.
• When the computer is first powered on, a small boot loader located in
nonvolatile firmware known as BIOS is run.
• This initial boot loader usually does nothing more than load a second
boot loader, which is located at a fixed disk location called the boot
block (it is simple code as it must fit in a single disk block) and knows
only the address on disk and the length of the remainder of the
bootstrap program).
• The program stored in the boot block may be sophisticated enough to
load the entire operating system into memory and begin its execution.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.19 Modified by Dr. Wafaa Samy
System Boot (Cont.)
 Modern systems replace BIOS with Unified Extensible Firmware Interface
(UEFI).
 Advantage: UEFI is a single, complete boot manager and therefore is
faster than the multistage BIOS boot process.

 Whether booting from BIOS or UEFI, the bootstrap program can perform a
variety of tasks.
• In addition to loading the file containing the kernel program into memory,
it also runs diagnostics to determine the state of the machine — for
example, inspecting memory and the CPU and discovering devices.
• If the diagnostics pass, the program can continue with the booting steps.
• The bootstrap can also initialize all aspects of the system, from CPU
registers to device controllers and the contents of main memory.
• Sooner or later, it starts the operating system and mounts the root file
system. It is only at this point is the system said to be running.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.20 Modified by Dr. Wafaa Samy
Design and Implementation

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.21 Modified by Dr. Wafaa Samy
Design and Implementation
 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: traditional
desktop/laptop, mobile, distributed, or real time.

 The requirements can be divided into: 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


Silberschatz, Galvin and Gagne ©2018 2.22 Modified by Dr. Wafaa Samy
Policy and Mechanism
 Policy: What needs to be done?
• Example: Interrupt after every 100 seconds.
 Mechanism: How to do something?
• Example: timer.
 The timer construct is a mechanism for ensuring CPU protection, but
deciding how long the timer is to be set for a particular user is a policy
decision.
 Important principle: separate policy from mechanism for flexibility.
 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


Silberschatz, Galvin and Gagne ©2018 2.23 Modified by Dr. Wafaa Samy
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.


• Advantages of using a higher-level language for implementing OSes:
the code can be written faster, is more compact, and is easier to
understand and debug. Besides, the OS is far easier to port to other
hardware.
• Disadvantages are reduced speed and increased storage requirements.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.24 Modified by Dr. Wafaa Samy
Operating System Structure

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.25 Modified by Dr. Wafaa Samy
Operating System Structure
 General-purpose OS is very large program.
• 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.

 Various ways to structure OSes:


• Simple structure – MS-DOS
• More complex – UNIX
• Layered – an abstraction
• Microkernel – Mach

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.26 Modified by Dr. Wafaa Samy
(1) Monolithic Structure – Original UNIX
 Monolithic structure: The simplest structure for organizing an
OS is no structure at all.
• Place all of the functionality of the kernel into a single, static binary file
that runs in a single address space.
• This approach is a common technique for designing OSes.
• An example of such limited structuring is the original UNIX OS.
 UNIX – limited by hardware functionality, the original UNIX
operating system had limited structuring.

 The original UNIX OS consists of two separable parts:


1. Systems programs.
2. 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 through system calls; a large
number of functions for one level.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.27 Modified by Dr. Wafaa Samy
(1) Monolithic Structure – Original UNIX (Cont.)
 The Linux operating system is based on UNIX and is structured similarly.
• The Linux kernel is monolithic in that it runs entirely in kernel mode in a
single address space, but it does have a modular design that allows the
kernel to be modified during run time.
 Advantages:
• The apparent simplicity of monolithic kernels.
• speed and efficiency: Monolithic kernels do have a distinct performance
advantage, however: there is very little overhead in the system-call
interface, and communication within the kernel is fast.
 Disadvantages:
• They are difficult to implement and extend.
 This is an enormous amount of functionality to be combined into one
single address space.
 Therefore, despite the drawbacks of monolithic kernels, their speed
and efficiency explains why we still see evidence of this structure in
the UNIX, Linux, and Windows operating systems.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.28 Modified by Dr. Wafaa Samy
Modularity – Loosely Coupled System
 The monolithic approach is often known as a tightly coupled system
because changes to one part of the system can have wide-ranging
effects on other parts.
 Alternatively, we could design a loosely coupled system.
• This system is divided into separate, smaller components that have (2
specific and limited functionality.
• All these components together comprise the kernel.

 Advantages:
• Changes in one component affect only that component, and no others,
allowing system implementers more freedom in creating and changing the
inner workings of the system.

 A system can be made modular in many ways.


• One method is the layered approach.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.29 Modified by Dr. Wafaa Samy
(2) Layered Approach
 The OS 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.
 Advantages: The main advantage of the layered approach is simplicity of
construction and debugging. If an error is found during the debugging of a
particular layer, the error must be on that layer, because the layers below it are
already debugged. Thus, the design and implementation of the system are
simplified.
 Disadvantages: Nevertheless, relatively few operating systems use a pure
layered approach.
• One reason involves the challenges of appropriately defining the
functionality of each layer.
• In addition, the overall performance of such systems is poor due to the
overhead of requiring a user program to traverse through multiple layers to
obtain an operating-system service.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.30 Modified by Dr. Wafaa Samy
(3) Microkernels
 This method structures the OS by removing all nonessential
components from the kernel and implementing them as user-level
programs that reside in separate address spaces.
 The result is a smaller kernel.
• Moves as much from the kernel into user space.
• Microkernels provide minimal process and memory management, in addition to
a communication facility.
 Mach OS is an example of microkernel:
• Mac OS X kernel (Darwin) partly based on Mach.
• Darwin consists of two kernels, one of which is the Mach microkernel.
 The main function of the microkernel is to provide communication
between the client program and the various services that are also
running in user space:
• Communication takes place between user modules using message passing.
• They communicate indirectly by exchanging messages with the microkernel.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.31 Modified by Dr. Wafaa Samy
Microkernel System Structure

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.32 Modified by Dr. Wafaa Samy
(3) Microkernels (Cont.)
 Advantages:
• Easier to extend a microkernel.
 All new services are added to user space and consequently do not require
modification of the kernel.
 When the kernel does have to be modified, the changes tend to be fewer,
because the microkernel is a smaller kernel.
• Easier to port the operating system to new architectures.
 OS is easier to port from one hardware design to another.
• More reliable (less code is running in kernel mode).
 since most services are running as user—rather than kernel—processes.
 If a service fails, the rest of the operating system remains untouched.
• More secure.
 Disadvantages:
• Performance overhead of user space to kernel space communication.
 The performance can suffer due to increased system-function overhead.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.33 Modified by Dr. Wafaa Samy
(4) Modules
 Perhaps the best current methodology for operating-system design
involves using loadable kernel modules (LKMs).
• This type of design is common in modern implementations of UNIX,
such as Linux, macOS, and Solaris, as well as Windows.

 The kernel has a set of core components and can link in


additional services via modules, either at boot time or during
run time.

 Many modern operating systems implement LKMs:


• 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.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.34 Modified by Dr. Wafaa Samy
(4) Modules (Cont.)
 Overall, similar to layers (each kernel section has defined, protected
interfaces) but with more flexible because any module can call any other
module:
• Linux, Solaris, etc.
 The approach is also similar to the microkernel approach in that
the primary module has only core functions and knowledge of
how to load and communicate with other modules;
• But it is more efficient, because modules do not need to invoke
message passing in order to communicate.

 Linux uses loadable kernel modules, primarily for supporting device


drivers and file systems.
• LKMs can be “inserted” into the kernel as the system is started (or
booted) or during run time, such as when a USB device is plugged
into a running machine.
• If the Linux kernel does not have the necessary driver, it can be
dynamically loaded.
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.35 Modified by Dr. Wafaa Samy
(5) Hybrid Systems
 Most modern operating systems are not one pure
model:
• Hybrid system combines multiple approaches (structures)
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 that run as user-mode processes.
Windows systems also provide support for dynamically
loadable kernel modules.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.36 Modified by Dr. Wafaa Samy
Operating System Debugging

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.37 Modified by Dr. Wafaa Samy
Operating-System Debugging
 Debugging is finding and fixing errors, or bugs in a system.
 Also performance tuning:
• Performance problems are considered bugs, so debugging can also
include performance tuning, which seeks to improve performance by
removing processing bottlenecks.

 OS generate log files containing error information.


• Failure of an application can generate core dump file capturing
memory of the process.
• OS failure can generate crash dump file containing kernel memory.

 Beyond crashes, performance tuning can optimize system


performance.
• Sometimes using trace listings of activities, recorded for analysis.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.38 Modified by Dr. Wafaa Samy
Performance Tuning
 Improve performance by removing bottlenecks.
 OS must provide means of computing and displaying measures of
system behavior. Tools may be characterized as providing either
per-process or system-wide observations.
 For example, “top” program or Windows Task Manager.

Operating System Concepts – 10th Edition


Silberschatz, Galvin and Gagne ©2018 2.39 Modified by Dr. Wafaa Samy
Operating System Concepts – 10th Edition
Silberschatz, Galvin and Gagne ©2018 2.40 Modified by Dr. Wafaa Samy

You might also like