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

OS Structure_System Calls

The document outlines the fundamental concepts and structures of operating systems, including services provided to users and processes, the role of the kernel, and the distinction between user mode and kernel mode. It details how system calls function as the interface between user applications and the operating system, enabling communication with hardware and resource management. Additionally, it discusses various types of system calls and their significance in maintaining system security and stability.

Uploaded by

anshdeeps1313
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

OS Structure_System Calls

The document outlines the fundamental concepts and structures of operating systems, including services provided to users and processes, the role of the kernel, and the distinction between user mode and kernel mode. It details how system calls function as the interface between user applications and the operating system, enabling communication with hardware and resource management. Additionally, it discusses various types of system calls and their significance in maintaining system security and stability.

Uploaded by

anshdeeps1313
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Operating-System Structures

Popular Operating Systems are:


Apple macOs | Microsoft windows | Google Android OS| Linux Operating System | Apple ios.

Operating System Concepts


Objectives

o To describe the services an operating system provides to users, processes, and other

systems

o To discuss the various ways of structuring an operating system

o To explain how operating systems are installed and customized and how they boot

o To understand the system structure of an Operating System and how is it designed?

Operating System Concepts


Objectives

How does an operating system enable

user application programs

to communicate with the

machine’s hardware?

A system structure for an operating system is like the


blueprint of
how an OS is organized and
how its different parts interact with each other.

Operating System Concepts


Operating-System Structures

o Operating System Services


o User Operating System Interface
o System Calls
o Types of System Calls
o System Programs
o Operating System Design and Implementation
o Operating System Structure
o Operating System Debugging
o Operating System Generation
o System Boot

Operating System Concepts


Operating System - Kernel
o The kernel is the core component of an operating system (OS)

o It serves as the intermediary between hardware and software.

o It manages system resources, including the CPU, memory, and I/O devices, and ensures that multiple
applications can run simultaneously without interfering with each other.

o Thus, kernel is responsible for essential tasks like process management, memory management, file
systems, and device control.

Operating System Concepts


Role of the Kernel in an Operating System

Resource Management:

• CPU Scheduling: The kernel decides which process or thread gets to use the CPU and for how long, ensuring
efficient execution and multitasking.

• Memory Management: It manages the allocation and deallocation of memory space to various programs. This
includes handling virtual memory, paging, and swapping.

• Device Management: The kernel controls and coordinates the use of hardware devices, such as disks, printers,
and network interfaces, through device drivers.

• File System Management: It manages file operations, including reading, writing, creating, and deleting files, as
well as ensuring data security and integrity.

Process Management:

• The kernel handles the creation, scheduling, and termination of processes. It manages process states, inter-
process communication (IPC), and synchronization between processes.

Operating System Concepts


Role of the Kernel in an Operating System

Security and Protection:

• The kernel enforces security policies, ensuring that applications cannot access unauthorized
memory areas or perform unauthorized operations. It also handles user permissions and protects
system integrity.

System Calls Interface:

• The kernel provides the system calls interface, which allows user programs to request services from
the operating system, such as file handling, process control, and device management.

Operating System Concepts


Two modes of an Operating System
o User mode and kernel mode are two
distinct operating modes in an operating
system

o The two modes separate the execution


environment of user applications from that
of the operating system's core (the kernel).

o This separation ensures system security,


stability, and efficient resource
management.

Operating System Concepts


Two modes of an Operating System (User Mode)
• Purpose: User mode is the execution mode in which user applications run. It is a restricted mode that
limits the access of applications to critical system resources and hardware.

• Access Level: Programs running in user mode cannot directly access hardware or system resources like
memory, I/O devices, or the CPU. They must use system calls to request services from the kernel, which
operates in kernel mode.

• Safety: Because user mode has restricted access, any crashes or bugs in user-mode programs are less
likely to affect the entire system. The operating system can isolate and handle such errors without
compromising overall stability.

Operating System Concepts


Two modes of an Operating System (Kernel Mode)
• Purpose: Kernel mode is the privileged execution mode where the operating system's kernel operates. It
has full access to all system resources, including hardware, memory, and all CPU instructions.

• Access Level: In kernel mode, the kernel can execute any CPU instruction and access any memory
address or hardware device. This unrestricted access allows the kernel to manage system resources
effectively and perform critical operations like process scheduling, memory management, and device
control.

• Risk: Since kernel mode has full system access, errors or bugs in the kernel can cause the entire system
to crash or become unstable. Therefore, only trusted, low-level code, such as the OS kernel and device
drivers, runs in this mode.

Operating System Concepts


Two modes of an Operating System (Kernel Mode)
Various examples of Privileged and Non – Privileged Instructions

• Privileged Instructions (run in Kernel Non-Privileged Instructions (run in


Mode) include:
User Mode) include:
• I/O instructions and Halt instructions
• Turn off all Interrupts • Reading the status of Processor
• Set the Timer
• Reading the System Time
• Context Switching
• Generate any Trap Instruction
• Clear the Memory or Remove a
process from the Memory
• Sending the final printout of Printer
• Modify entries in the Device-status
table • Limited access to system resources
• Direct access to system resources

Operating System Concepts


Two modes of an Operating System
• User Mode: Restricted access, where user applications run. It
ensures that applications cannot directly interfere with system
resources, providing a safer and more stable environment.

• Instructions - > Non - privileged

• Kernel Mode: Unrestricted access, where the operating


system's kernel runs. It allows the kernel to manage and control
system resources, but with higher risks if errors occur.

• Instructions - > Privileged

This dual-mode operation is fundamental to maintaining the


security and reliability of modern operating systems.

Operating System Concepts


Operating System Services
Operating systems provide an environment for execution of programs and services to programs and users

o 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)

• 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

Operating System Concepts


Operating System Services (Cont.)
One set of operating-system services provides functions that are helpful to the user (Cont.):

• File-system manipulation - Programs need to read and write files and directories, create and delete them, search
them, list file Information, permission management.

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

• 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 efficiently use the system

Operating System Concepts


Operating System Services (Cont.)

o Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing

• Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to
each of them

▪ Many types of resources - CPU cycles, main memory, file storage, I/O devices.

• Accounting - To keep track of which users use how much and what kinds of computer resources

• Protection and security - The owners of information stored in a multiuser or networked computer system may want
to control use of that information, concurrent processes should not interfere with each other

▪ Protection involves ensuring that all access to system resources is controlled

▪ Security of the system from outsiders requires user authentication, extends to defending external I/O devices
from invalid access attempts

Operating System Concepts


A View of Operating System Services

Operating System Concepts


User Operating System Interface - CLI

CLI or command interpreter allows direct command entry

• Sometimes implemented in kernel, sometimes by systems program

• Sometimes multiple flavors implemented – shells

• Primarily fetches a command from user and executes it

• Sometimes commands built-in, sometimes just names of programs

▪ If the latter, adding new features doesn’t require shell modification

Operating System Concepts


Bourne Shell Command Interpreter

Operating System Concepts


User Operating System Interface - GUI

o User-friendly desktop metaphor interface


• Usually mouse, keyboard, and monitor
• Icons represent files, programs, actions, etc
• Various mouse buttons over objects in the interface cause various actions (provide
information, options, execute function, open directory (known as a folder)
• Invented at Xerox PARC

o Many systems now include both CLI and GUI interfaces


• Microsoft Windows is GUI with CLI “command” shell
• Apple Mac OS X is “Aqua” GUI interface with UNIX kernel underneath and shells
available
• Unix and Linux have CLI with optional GUI interfaces (CDE, KDE, GNOME)

Operating System Concepts


Touchscreen Interfaces

n Touchscreen devices require new interfaces

l Mouse not possible or not desired

l Actions and selection based on gestures

l Virtual keyboard for text entry

l Voice commands.

Operating System Concepts


The Mac OS X GUI

Operating System Concepts


System Calls

o System calls in an operating system are the fundamental interface between a


running program (usually an application) and the operating system itself.

o They allow user-level processes to request services from the kernel of the operating
system.

o These services include performing tasks such as accessing hardware resources


(e.g., memory, disk, or network), creating and managing processes, and handling
files and directories.

o Role in the Operating System:

• System calls act as a gateway for user programs to interact with the underlying
hardware and system resources.

• Since user programs typically do not have direct access to the hardware or
critical resources, they must go through system calls to request such access.

Operating System Concepts


System Calls

o Programming interface to the services provided by the OS

o Typically written in a high-level language (C or C++)

o Mostly accessed by programs via a high-level Application Programming Interface (API)

rather than direct system call use

o Four 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),
• Linux API, System calls and libraries specific to the Linux kernel.

Note that the system-call names used throughout this text are generic
Operating System Concepts
Types of System Calls

• Process Control: Includes system calls for process creation, termination, and management (e.g., fork(),
exec(), exit(), wait()).

• File Management: Deals with file operations like creation, deletion, reading, writing, and setting
attributes (e.g., open(), read(), write(), close()).

• Device Management: Used to request device operations or manage device inputs and outputs (e.g.,
ioctl(), read(), write()).

• Information Maintenance: Includes system calls for getting or setting the system data (e.g., getpid() to
get process ID, alarm() to set timers).

• Communication: Used for inter-process communication, including sending and receiving messages,
establishing and managing connections (e.g., pipe(), shmget() for shared memory, send(), recv() for
network communication).

Operating System Concepts


How System Calls work?
o When a user program makes a system call, it

typically executes a software interrupt or a


specific instruction that switches the mode of
the CPU from user mode to kernel mode.

o In kernel mode, the operating system has


unrestricted access to all machine resources.

o The OS then executes the requested service


and returns the result to the user program,
switching back to user mode afterward.

Operating System Concepts


How System Calls work?

Operating System Concepts


Importance of System Calls
• They provide a controlled interface to hardware resources, ensuring user programs do not disrupt hardware,
preventing instability or security issues.

• They maintain abstraction between applications and hardware, enabling developers to write programs without
concern for hardware specifics.

Operating System Concepts


Example of System Calls

o System call sequence to copy the contents of one file to another file

Operating System Concepts


Example of Standard API

Operating System Concepts


System Call Implementation

o Typically, a number associated with each system call

• System-call interface maintains a table indexed according to these numbers

o The system call interface invokes the intended system call in OS kernel and returns status of

the system call and any return values

o 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


Relationship Between the Kernel and System Calls
• System Calls as an Interface:
• System calls are the primary way user-space applications communicate with the kernel.
• When an application needs to perform an operation that requires access to hardware or other privileged resources, it
makes a system call
• Kernel Mode vs. User Mode:
• The CPU operates in two modes: user mode and kernel mode.
• Applications run in user mode, where they have limited access to system resources.
• When a system call is made, the CPU switches to kernel mode, where the kernel has full access to all hardware and
system resources.
• Execution of System Calls:
• When an application makes a system call, control is transferred to the kernel, which executes the requested operation on
behalf of the application.
• After completing the operation, the kernel returns the result to the application and switches back to user mode.
• Abstraction and Security:
• The kernel abstracts the complexity of hardware operations from user programs.
• System calls ensure that applications do not directly interact with hardware, which maintains security and stability.
• The kernel validates and manages system call requests to prevent unauthorized or harmful operations.

Operating System Concepts


API – System Call – OS Relationship

Operating System Concepts


System Call Parameter Passing

o Often, more information is required than simply identity of desired system call

• Exact type and amount of information vary according to OS and call

o 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

Operating System Concepts


Parameter Passing via Table

Operating System Concepts


Types of System Calls
o 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
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to shared data between processes

Operating System Concepts


Types of System Calls

o File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
o Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices

Operating System Concepts


Types of System Calls (Cont.)

o Information maintenance
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
o Communications
• 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


Types of System Calls (Cont.)

o Protection
• Control access to resources
• Get and set permissions
• Allow and deny user access

Operating System Concepts


Examples of Windows and Unix System Calls

Operating System Concepts


Standard C Library Example

o C program invoking printf() library call, which calls write() system call

Operating System Concepts


Example: MS-DOS

o Single-tasking
o Shell invoked when
system booted
o Simple method to run
program
• No process created
o Single memory space
o Loads program into
memory, overwriting all
but the kernel
o Program exit -> shell
reloaded At system startup running a program

Operating System Concepts


Example: FreeBSD
o Unix variant
o Multitasking
o User login -> invoke user’s choice of
shell
o 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
o Process exits with:
• code = 0 – no error
• code > 0 – error code

Operating System Concepts


System Programs

o System programs provide a convenient environment for program development and execution.
They can be divided into:
• File manipulation
• Status information sometimes stored in a File modification
• Programming language support
• Program loading and execution
• Communications
• Background services
• Application programs
o Most users’ view of the operation system is defined by system programs, not the actual system
calls

Operating System Concepts


System Programs
o Provide a convenient environment for program development and execution
• Some of them are simply user interfaces to system calls; others are
considerably more complex

o File management - Create, delete, copy, rename, print, dump, list, and
generally manipulate files and directories

o Status information
• Some ask the system for info - date, time, amount of available memory,
disk space, number of users
• Others provide detailed performance, logging, and debugging information
• Typically, these programs format and print the output to the terminal or
other output devices
• Some systems implement a registry - used to store and retrieve
configuration information

Operating System Concepts


System Programs (Cont.)

o File modification

• Text editors to create and modify files

• Special commands to search contents of files or perform transformations of the text

o Programming-language support - Compilers, assemblers, debuggers and interpreters sometimes


provided

o Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-
loaders, debugging systems for higher-level and machine language

o 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 electronic-mail
messages, log in remotely, transfer files from one machine to another

Operating System Concepts


System Programs (Cont.)
o 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

o 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


Operating System Design and Implementation

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


approaches have proven successful

o Internal structure of different Operating Systems can vary


widely

o Start the design by defining goals and specifications

o Affected by choice of hardware, type of system

o 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

Operating System Concepts


Operating System Design and Implementation (Cont.)

o Important principle to separate


Policy: What will be done?
Mechanism: How to do it?
o Mechanisms determine how to do something, policies
decide what will be done
o The separation of policy from mechanism is a very
important principle, it allows maximum flexibility if policy
decisions are to be changed later (example – timer)
o Specifying and designing an OS is highly creative task of
software engineering

Operating System Concepts


Implementation

o Much variation
• Early OSes in assembly language
• Then system programming languages like Algol, PL/1
• Now C, C++
o 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
o More high-level language easier to port to other hardware
• But slower
o Emulation can allow an OS to run on non-native hardware

Operating System Concepts


Operating System Structure
o General-purpose OS is very large program
o Various ways to structure ones
• Simple structure – MS-DOS
• More complex -- UNIX
• Layered – an abstrcation
• Microkernel -Mach

Operating System Concepts


Simple Structure -- MS-DOS

o 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

Operating System Concepts


Non Simple Structure -- 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

Operating System Concepts


Traditional UNIX System Structure
Beyond simple but not fully layered

Operating System Concepts


Layered Approach

o 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.
o With modularity, layers are
selected such that each
uses functions (operations)
and services of only lower-
level layers

Operating System Concepts


Microkernel System Structure
o Moves as much from the kernel into user space
o Mach example of microkernel
• Mac OS X kernel (Darwin) partly based on Mach
o Communication takes place between user modules
using message passing
o 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
o Detriments:
• Performance overhead of user space to kernel
space communication
Operating System Concepts
Microkernel System Structure

Application File Device user


Program System Driver mode

messages messages

Interprocess memory CPU kernel


Communication managment scheduling mode

microkernel

hardware

Operating System Concepts


Modules

o Many 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
o Overall, similar to layers but with more flexible
• Linux, Solaris, etc

Operating System Concepts


Solaris Modular Approach

Operating System Concepts


Hybrid Systems

o Most modern operating systems are 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
o 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)

Operating System Concepts


Mac OS X Structure

graphical user interface


Aqua

application environments and services

Java Cocoa Quicktime BSD

kernel environment
BSD

Mach

I/O kit kernel extensions

Operating System Concepts


iOS

o 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

Operating System Concepts


Android
o Developed by Open Handset Alliance (mostly Google)
• Open Source
o Similar stack to IOS
o Based on Linux kernel but modified
• Provides process, memory, device-driver management
• Adds power management
o 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
o Libraries include frameworks for web browser (webkit),
database (SQLite), multimedia, smaller libc

Operating System Concepts


AndroidApplications
Architecture

Application Framework

Libraries Android runtime

SQLite openGL Core Libraries

surface media
Dalvik
manager framework
virtual machine
webkit libc

Linux kernel

Operating System Concepts


Operating-System Debugging

o Debugging is finding and fixing errors, or bugs


o OS generate log files containing error information
o Failure of an application can generate core dump file capturing
memory of the process
o Operating system failure can generate crash dump file
containing kernel memory
o Beyond crashes, performance tuning can optimize system
performance
• Sometimes using trace listings of activities, recorded for
analysis
• Profiling is periodic sampling of instruction pointer to look
for statistical trends
Kernighan’s Law: “Debugging is twice as hard as writing the code
in the first place. Therefore, if you write the code as cleverly as
possible, you are, by definition, not smart enough to debug it.”
Operating System Concepts
System Boot

o When power initialized on system, execution starts at a fixed memory location


• Firmware ROM used to hold initial boot code
o Operating system must be made available to hardware so hardware can start it
• Small piece of code – bootstrap loader, stored in ROM or EEPROM locates the
kernel, loads it into memory, and starts it
• Sometimes two-step process where boot block at fixed location loaded by ROM
code, which loads bootstrap loader from disk
o Common bootstrap loader, GRUB, allows selection of kernel from multiple disks,
versions, kernel options
o Kernel loads and system is then running

Operating System Concepts

You might also like