Sei sulla pagina 1di 19

OS Structure, Processes & Process Management

OPERATING SYSTEM OVERVIEW


WHAT IS AN OPERATING SYSTEM?

An interface between users and hardware - an environment "architecture Allows convenient usage; hides the tedious stuff

Allows efficient usage; parallel activity, avoids wasted cycles


Provides information protection Gives each user a slice of the resources Acts as a control program.

These are the pieces of the system Process Management Main Memory Management File Management I/O System Management Secondary Management Networking Protection System Command-Interpreter System

PROCESS MANAGEMENT A process is a program in execution: (A program is passive, a process active.) A process has resources (CPU time, files) and attributes that must be managed. Management of processes includes:

Process Scheduling (priority, time management, . . . ) Creation/termination Block/Unblock (suspension/resumption ) Synchronization Communication Deadlock handling Debugging

MAIN MEMORY MANAGEMENT Allocation/de-allocation for processes, files, I/O. Maintenance of several processes at a time Keep track of who's using what memory Movement of process memory to/from secondary storage. FILE MANAGEMENT A file is a collection of related information defined by its creator. Commonly, files represent programs (both source and object forms) and data. The operating system is responsible for the following activities in connections with file management: File creation and deletion. Directory creation and deletion. Support of primitives for manipulating files and directories. Mapping files onto secondary storage. File backup on stable (nonvolatile) storage media.
5

SYSTEM STRUCTURES

System Components

I/O MANAGEMENT Buffer caching system Generic device driver code Drivers for each device - translate read/write requests into disk position commands.

SECONDARY STORAGE MANAGEMENT Disks, tapes, optical, ... Free space management ( paging/swapping )

Storage allocation ( what data goes where on disk )


Disk scheduling

NETWORKING Communication system between distributed processors. Getting information about files/processes/etc. on a remote machine. Can use either a message passing or a shared memory model. PROTECTION Of files, memory, CPU, etc. Means controlling of access Depends on the attributes of the file and user SYSTEM PROGRAMS Command Interpreters interface, etc.) -- Program that accepts control statements (shell, GUI

Compilers/linkers
Communications (ftp, telnet, etc.)

Recap

OS functions
Coordinator

Service provider

Protection Communication Resource management File system, device handler,

The CPU is wasted if a job waits for I/O. This leads to:

Multiprogramming ( dynamic switching ). While one job waits for a resource, the CPU can find another job to run. It means that several jobs are ready to run and only need the CPU in order to continue.
All of this leads to: memory management resource scheduling deadlock protection which are the subject of the rest of this course.

OPERATING SYSTEM OVERVIEW


Other Characteristics include:

Characteristics

Time Sharing - multiprogramming environment that's also interactive. Multiprocessing - Tightly coupled systems that communicate via shared memory. Used for scientific applications. Used for speed improvement by putting together a number of off-the-shelf processors.

Distributed Systems - Loosely coupled systems that communicate via message passing. Advantages include resource sharing, speed up, reliability, communication.

Real Time Systems - Rapid response time is main characteristic. Used in control of applications where rapid response to a stimulus is essential.
10

An Operating System in Action


CPU loads boot program from ROM (e.g. BIOS in PCs) Boot program:
Examines/checks machine configuration (number of CPUs, how much memory, number & type of hardware devices, etc.) Builds a configuration structure describing the hardware Loads the operating system, and gives it the configuration structure

Operating system initialization:

Initialize kernel data structures Initialize the state of all hardware devices Creates a number of processes to start operation (e.g. getty in UNIX, the Windowing system in NT, e.g.)

11

O.S. in Action (Contd)


After basic processes have started, the OS runs user programs, if available, otherwise enters the idle loop

In the idle loop:

OS executes an infinite loop (UNIX) OS performs some system management & profiling OS halts the processor and enter in low-power mode (notebooks) Interrupts from hardware devices Exceptions from user programs System calls from user programs User mode: Restricted execution mode (applications) Supervisor mode: Unrestricted access to everything (OS)

OS wakes up on:

Two modes of execution

12

Control Flow in an OS
main() From boot Interrupt

Initialization

System call
Exception

Idle Loop Operating System Modules


Supervisor Mode

RTI
Return to user mode
13

OPERATING SYSTEM OVERVIEW


Interrupts:

Characteristics

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. Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt. A trap is a software-generated interrupt caused either by an error or a user request. An operating system is interrupt driven.

14

On Interrupts
Hardware calls the operating system at a pre-specified location Operating system saves state of the user program Operating system identifies the device and cause of interrupt Responds to the interrupt Operating system restores state of the user program (if applicable) or some other user program Execute an RTI instruction to return to the user program User program continues exactly at the same point it was interrupted. Key Fact: None of this is visible to the user program

15

On Exceptions
Hardware calls the operating system at a pre-specified location Operating system identifies the cause of the exception (e.g. divide by 0) If user program has exception handling specified, then OS adjust the user program state so that it calls its handler Execute an RTI instruction to return to the user program If user program did not have a specified handler, then OS kills it and runs some other user program, as available Key Fact: Effects of exceptions are visible to user programs and cause abnormal execution flow

16

On System Calls
User program executes a trap instruction (system call) Hardware calls the operating system at a pre-specified location Operating system identifies the required service and parameters (e.g. open(filename, O_RDONLY)) Operating system executes the required service Operating system sets a register to contain the result of call Execute an RTI instruction to return to the user program User program receives the result and continues Key Fact: To the user program, it appears as a function call executed under program control

17

Operating System Today


High-level software architecture

User Applications Command Interpreter Window System Middleware Operating System (process/device/memory management, file systems, interprocess communication, ) Instruction Execution & Interrupt Processing I/O Devices Memory

18

Summary
An OS is just a program:
It has a main() function, which gets called only once (during boot) Like any program, it consumes resources (such as memory), can do silly things (like generating an exception), etc.

But it is a very strange program:


It is entered from different locations in response to external events It does not have a single thread of control, it can be invoked simultaneously by two different events (e.g. system call & an interrupt) It is not supposed to terminate It can execute any instruction in the machine

19

Potrebbero piacerti anche