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

Operating Systems

Uploaded by

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

Operating Systems

Uploaded by

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

1

Operating Systems
Chapter 1: Introduction
Faculty of Computers and Artificial Intelligence

Computer System Structure

Computer system can be divided into four components:


• Hardware – provides basic computing resources
➢ CPU, memory, I/O devices
• Operating system
➢ Controls and coordinates use of hardware among various applications and
users
• Application programs
➢ define the ways in which the system resources are used to solve the
computing problems of the users. Ex. Word processors, compilers, web
browsers, database systems, video games.
• Users
➢ People, machines, other computers
2

What is an Operating System?


An operating system is a program that manages a
computer’s hardware. It also provides a basis for
application programs and acts as an intermediary
between the computer user and the computer hardware

Operating system goals


Execute user programs and make solving user problems
easier
Make the computer system convenient to use
Use the computer hardware in an efficient manner

What Operating Systems Do?


User View
• Users want convenience, ease of use and good
performance.
➢ Don’t care about resource utilization.
• But shared computer such as mainframe or
minicomputer must keep all users happy

System View
● The operating system is closely tied to the hardware, serving as a
resource allocator.
● It manages various resources like CPU time, memory, file storage,
and I/O devices in a computer system.
● acts as the manager of these resources
3

• OS is a resource allocator
➢ Manages all resources.
➢ Decides between conflicting requests for efficient and fair
resource use.

• OS is a control program
➢ Controls execution of programs to prevent errors and
improper use of the computer.

A more common definition, and the one that we usually


follow, is that the operating system is the one program
running at all times on the computer—usually called the
kernel.

• (Along with the kernel, there are two other types of


programs: system programs, which are associated with
the operating system but are not necessarily part of the
kernel, and application programs, which include all
programs not associated with the operation of the
system.)

Computer System Organization

A modern general-purpose computer system consists of


one or more CPUs and a number of device controllers
connected through a common bus that provides access to
shared memory
4

Computer Startup
• bootstrap program is loaded at power-up or reboot
➢ Typically stored in ROM or electrically erasable
programmable read-only memory (EPROM), generally known
as firmware.
➢ Initializes all aspects of system.
➢ Loads operating system kernel and starts execution.

Interrupts
• The occurrence of an event is usually signaled by an
interrupt from either the hardware or the software.

➢ Hardware may trigger an interrupt at any time by sending a


signal to the CPU, usually by way of the system bus.

➢ Software may trigger an interrupt by executing a special


operation called a system call (also called a monitor call).

• Interrupts are an important part of a computer


architecture. Each computer design has its own interrupt
mechanism, but several functions are common.

• Interrupt transfers control to the interrupt service routine


generally, through the interrupt vector, which contains
the addresses of all the service routines.

• Interrupt architecture must save the address of the


interrupted instruction.

• A trap or exception is a software-generated interrupt


caused either by an error or a user request.
• An operating system is interrupt driven.
5
Storage Structure (1/4)
The basic unit of computer storage is the bit, A byte is 8 bits

A less common term is word, which is a given computer architecture’s


native unit of data. A word is made up
of one or more bytes. For example, a computer that has 64-bit registers
and 64-bit memory addressing typically has 64-bit (8-byte) words.

A kilobyte, or KB, is 1,024 bytes


a megabyte, or MB, is 1,0242 bytes
a gigabyte, or GB, is 1,0243 bytes
a terabyte, or TB, is 1,0244 bytes
a petabyte, or PB, is 1,0245 bytes

Main memory
–only large storage media that the CPU can access
directly.
➢ Random access
➢ Typically volatile

Secondary storage
– extension of main memory that provides large
nonvolatile storage capacity

➢Hard disks ➢ Solid-state disks


6
How a Modern Computer Works

Multiprocessing Architecture (1/2)

• Multiprocessors systems growing in use and importance


➢ Also known as parallel systems.
➢ Advantages include:

1. Increased throughput: by increasing the number of processors, we


expect to get more work done in less time.
2. Economy of scale: Multiprocessor systems can cost less than
equivalent multiple single-processor systems, because they can share
peripherals, mass storage, and power supplies.
3. Increased reliability: graceful degradation or fault tolerance

➢ Two types:

1. Asymmetric Multiprocessing – each processor is assigned a specific task.


2. Symmetric Multiprocessing – each processor performs all tasks.
7

Symmetric Multiprocessing

A Dual-Core Design
Multi-chip and multicore

Operating-System Structure (1/3)

• Multiprogramming (Batch system) needed for efficiency.

➢ Single user cannot keep CPU and I/O devices busy at all times
➢ Multiprogramming organizes jobs (code and data) so CPU always has
one to execute
➢ A subset of total jobs in system is kept in memory
➢ One job selected and run via job scheduling
➢ When it has to wait (for I/O for example), OS switches to
another job
8

• Timesharing (multitasking) is logical extension in which


CPU switches jobs so frequently that users can interact with
each job while it is running, creating
interactive computing

➢ Response time should be < 1 second


➢ Each user has at least one program executing in memory →
process
➢ If several jobs ready to run at the same time → CPU scheduling
➢ If processes don’t fit in memory, swapping moves them in and out
to run
➢ Virtual memory allows execution of processes not completely in
memory

Operating-System Operations (1/4)

• Interrupt driven (hardware and software)


• Hardware interrupt by one of the devices
• Software interrupt (exception or trap):
➢ Software error (e.g., division by zero)
➢ Request for operating system service
➢ Other process problems include infinite loop, processes
modifying each other or the operating system

• Dual-mode operation allows OS to protect itself and


other system components
• User mode and kernel mode (also called supervisor
mode, system mode, or privileged mode)
9
A bit, called the mode bit, is added to the hardware of the computer to
indicate the current mode: kernel (0) or user (1).
➢ Provides ability to distinguish when system is running user code or
kernel code.
➢ Some instructions designated as privileged, only executable in kernel
mode.
➢ System call changes mode to kernel, return from call resets it
to the user.

Levels of Storage
10

Protection and Security


• Protection – any mechanism for controlling access of
processes or users to resources defined by the OS.
• Security – defense of the system against internal and
external attacks.
➢ Huge range, including denial-of-service, worms,
viruses, etc.

Chapter 2: Operating-System Structures


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

➢ User interface - Almost all operating systems have a user


interface (UI)
• Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch

➢ 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.
11
➢ 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.

➢ 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.
• Debugging facilities can greatly enhance the user’s and
programmer’s abilities to efficiently use the system.

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
12

User Operating System Interface (1/5)


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

• Graphics User Interface (GUI)


• 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).
• Many systems now include both CLI and GUI interfaces.

• Touchscreen Interfaces
• Touchscreen devices require new interfaces.
➢ Mouse not possible or not desired.
➢ Actions and selection based on gestures.
➢ Virtual keyboard for text entry.
• Voice commands.

System Calls (1/6)


Programming interface to the services provided by the OS
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)
13

Types of System Calls (1/6)

1. Process control
2. File management
3. Device management
4. Information maintenance
5. Communications
6. Protection

System Programs (1/5)


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

OS Design and Implementation (1/3)

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

Operating System Structure (2/8)

• General-purpose OS is very large program.


• Various ways to structure ones:
➢ Simple structure – MS-DOS
➢ More complex – UNIX
➢ Layered
➢ Microkernel – Mach

The UNIX OS consists of two separable parts:


• Systems programs
• The kernel

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
15
16

Chapter 3: Processes
Program vs. Process
• A program is a passive entity such as the file that
contains the list of instructions stored on a disk always
referred to as an executable file.
• A program becomes a process when an executable file is
loaded into the memory and then becomes an active
entity

• The fundamental task of any operating system is the


process management.

• OS must allocate resources to processes, enable sharing


of information, protect resources, and enable the
synchronization among processes

Process Elements (1/2)

➢ Text Section: the program code. This is typically read-only,


and might be shared by a number of processes.

➢ Data Section: containing global variables.


➢ Heap: containing memory dynamically allocated during run
Time.

➢ Stack: containing temporary data.


• Function parameters, return addresses, local variables.
17

Process Control Block (PCB)

➢ Process identification information


➢ Processor state Information
▪ Process state – running, waiting, etc
➢ Program counter
▪ location of instruction to next execute
➢ CPU registers
▪ contents of all process-centric registers
➢ CPU scheduling information
▪ priorities, scheduling queue pointers
➢ Memory-management information
▪ memory allocated to the process
➢ Accounting information
▪ CPU used, clock time elapsed since start, time limits
➢ I/O status information
▪ I/O devices allocated to process, list of open files

Process State (1/3)

• As a process executes, it changes state


➢ new: The process is being created
➢ running: Instructions are being executed
➢ waiting: The process is waiting for some event to occur
➢ ready: The process is waiting to be assigned to a processor
➢ terminated: The process has finished execution
18

• Job queue – set of all processes in the system


• Ready queue – set of all processes residing in main memory,
ready and waiting to execute
• Device queues – set of processes waiting for an I/O device
• Processes migrate among the various queues
19

Schedulers (1/2)

• Short-term scheduler (or CPU scheduler)


➢ Selects which process should be executed next and allocates
CPU.
➢ Invoked frequently (milliseconds) → (must be fast).
• Long-term scheduler (or job scheduler)
➢ Selects which processes should be brought into the ready
queue.
➢ Invoked infrequently (seconds, minutes) → (may be slow).
➢ Controls the degree of multiprogramming

• Medium-term scheduler
➢ Can be added if degree of multiple programming needs to
decrease
➢ Remove process from memory, store on disk, bring back in
from disk to continue execution: swapping
20

Interprocess Communication (1/2)

• Processes within a system may be independent or


cooperating
• Cooperating process can affect or be affected by other
processes, including sharing data.
• Cooperating processes need interprocess communication
(IPC)
• Two models of IPC:
➢ Shared memory
➢ Message passing
21

Chapter 4: Threads

• A thread is a basic unit of CPU utilization; it comprises


a thread ID, a program counter, a register set, and a
stack.
• It shares with other threads belonging to the same
process its code section, data section, and other
operating-system resources, such as open files and
signals.

• Most software applications that run on modern


computers are multithreaded.
• An application typically is implemented as a separate
process with several threads of control.

Support for threads may be provided either at the user


level, for user threads, or by the kernel, for kernel
threads.

Multithreading Models (2/6)

• We look at three common models:


➢ the one-to-one model,
➢ the many-to-one model, and
➢ the many-to-many model.
22

Benefits of Threads
• Responsiveness – may allow continued execution if part
of process is blocked, especially important for user
interfaces.
• Resource Sharing – threads share resources of process,
easier than shared memory or message passing.
• Economy – cheaper than process creation, thread
switching lower overhead than context switching.
• Scalability
process can take advantage of
multiprocessor architectures.

Chapter 5: CPU Scheduling

You might also like