Sunteți pe pagina 1din 68

Process Concept

An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks
Textbook uses the terms job and process almost

interchangeably. Process a program in execution; process execution must progress in sequential fashion. A process includes:
program counter stack data section

Operating System Concepts

19.1

Silberschatz, Galvin and Gagne 2002

Process State

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 process. terminated: The process has finished execution.

Operating System Concepts

19.2

Silberschatz, Galvin and Gagne 2002

Diagram of Process State

Operating System Concepts

19.3

Silberschatz, Galvin and Gagne 2002

Process Control Block (PCB)


Information associated with each process. Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information

Operating System Concepts

19.4

Silberschatz, Galvin and Gagne 2002

Process Control Block (PCB)

Operating System Concepts

19.5

Silberschatz, Galvin and Gagne 2002

CPU Switch From Process to Process

Operating System Concepts

19.6

Silberschatz, Galvin and Gagne 2002

The Deadlock Problem


A set of blocked processes each holding a resource and

waiting to acquire a resource held by another process in the set. Example


System has 2 tape drives.

P1 and P2 each hold one tape drive and each needs another

one. Example semaphores A and B, initialized to 1

P0 wait (A); wait (B);

P1 wait(B) wait(A)

Operating System Concepts

19.7

Silberschatz, Galvin and Gagne 2002

Bridge Crossing Example

Traffic only in one direction. Each section of a bridge can be viewed as a resource. If a deadlock occurs, it can be resolved if one car backs

up (preempt resources and rollback). Several cars may have to be backed up if a deadlock occurs. Starvation is possible.

Operating System Concepts

19.8

Silberschatz, Galvin and Gagne 2002

Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously.
Mutual exclusion: only one process at a time can use a

resource. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task. Circular wait: there exists a set {P0, P1, , P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, , Pn1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0.

Operating System Concepts

19.9

Silberschatz, Galvin and Gagne 2002

Methods for Handling Deadlocks


Ensure that the system will never enter a deadlock state.
Allow the system to enter a deadlock state and then

recover.
Ignore the problem and pretend that deadlocks never

occur in the system; used by most operating systems, including UNIX.

Operating System Concepts

19.10

Silberschatz, Galvin and Gagne 2002

Deadlock Prevention

Restrain the ways request can be made.


Mutual Exclusion not required for sharable resources;

must hold for nonsharable resources.


Hold and Wait must guarantee that whenever a

process requests a resource, it does not hold any other resources.


Require process to request and be allocated all its

resources before it begins execution, or allow process to request resources only when the process has none. Low resource utilization; starvation possible.

Operating System Concepts

19.11

Silberschatz, Galvin and Gagne 2002

Deadlock Prevention (Cont.)


No Preemption If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released. Preempted resources are added to the list of resources for which the process is waiting. Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting.
Circular Wait impose a total ordering of all resource

types, and require that each process requests resources in an increasing order of enumeration.

Operating System Concepts

19.12

Silberschatz, Galvin and Gagne 2002

Deadlock Avoidance
Requires that the system has some additional a priori information available.
Simplest and most useful model requires that each

process declare the maximum number of resources of each type that it may need.
The deadlock-avoidance algorithm dynamically examines

the resource-allocation state to ensure that there can never be a circular-wait condition.
Resource-allocation state is defined by the number of

available and allocated resources, and the maximum demands of the processes.

Operating System Concepts

19.13

Silberschatz, Galvin and Gagne 2002

Chapter 9: Memory Management


Background
Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

Operating System Concepts

19.14

Silberschatz, Galvin and Gagne 2002

Background
Program must be brought into memory and placed within

a process for it to be run.


Input queue collection of processes on the disk that are

waiting to be brought into memory to run the program.


User programs go through several steps before being

run.

Operating System Concepts

19.15

Silberschatz, Galvin and Gagne 2002

Binding of Instructions and Data to Memory


Address binding of instructions and data to memory addresses can happen at three different stages.
Compile time: If memory location known a priori,

absolute code can be generated; must recompile code if starting location changes. Load time: Must generate relocatable code if memory location is not known at compile time. Execution time: Binding delayed until run time if the process can be moved during its execution from one memory segment to another. Need hardware support for address maps (e.g., base and limit registers).

Operating System Concepts

19.16

Silberschatz, Galvin and Gagne 2002

Logical vs. Physical Address Space


The concept of a logical address space that is bound to a

separate physical address space is central to proper memory management.


Logical address generated by the CPU; also referred to as

virtual address. Physical address address seen by the memory unit. Logical and physical addresses are the same in compile-

time and load-time address-binding schemes; logical (virtual) and physical addresses differ in execution-time address-binding scheme.

Operating System Concepts

19.17

Silberschatz, Galvin and Gagne 2002

Memory-Management Unit (MMU)


Hardware device that maps virtual to physical address.
In MMU scheme, the value in the relocation register is

added to every address generated by a user process at the time it is sent to memory.
The user program deals with logical addresses; it never

sees the real physical addresses.

Operating System Concepts

19.18

Silberschatz, Galvin and Gagne 2002

Dynamic relocation using a relocation register

Operating System Concepts

19.19

Silberschatz, Galvin and Gagne 2002

Dynamic Loading
Routine is not loaded until it is called
Better memory-space utilization; unused routine is never

loaded. Useful when large amounts of code are needed to handle infrequently occurring cases. No special support from the operating system is required implemented through program design.

Operating System Concepts

19.20

Silberschatz, Galvin and Gagne 2002

Dynamic Linking
Linking postponed until execution time.
Small piece of code, stub, used to locate the appropriate

memory-resident library routine. Stub replaces itself with the address of the routine, and executes the routine. Operating system needed to check if routine is in processes memory address. Dynamic linking is particularly useful for libraries.

Operating System Concepts

19.21

Silberschatz, Galvin and Gagne 2002

Swapping
A process can be swapped temporarily out of memory to a

backing store, and then brought back into memory for continued execution.
Backing store fast disk large enough to accommodate copies

of all memory images for all users; must provide direct access to these memory images.
Roll out, roll in swapping variant used for priority-based

scheduling algorithms; lower-priority process is swapped out so higher-priority process can be loaded and executed.
Major part of swap time is transfer time; total transfer time is

directly proportional to the amount of memory swapped.


Modified versions of swapping are found on many systems, i.e.,

UNIX, Linux, and Windows.

Operating System Concepts

19.22

Silberschatz, Galvin and Gagne 2002

Schematic View of Swapping

Operating System Concepts

19.23

Silberschatz, Galvin and Gagne 2002

Contiguous Allocation
Main memory usually into two partitions: Resident operating system, usually held in low memory with interrupt vector. User processes then held in high memory. Single-partition allocation Relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data. Relocation register contains value of smallest physical address; limit register contains range of logical addresses each logical address must be less than the limit register.

Operating System Concepts

19.24

Silberschatz, Galvin and Gagne 2002

Hardware Support for Relocation and Limit Registers

Operating System Concepts

19.25

Silberschatz, Galvin and Gagne 2002

Contiguous Allocation (Cont.)


Multiple-partition allocation Hole block of available memory; holes of various size are scattered throughout memory. When a process arrives, it is allocated memory from a hole large enough to accommodate it. Operating system maintains information about: a) allocated partitions b) free partitions (hole)

OS process 5

OS process 5

OS process 5 process 9

OS process 5 process 9 process 10

process 8 process 2 process 2 process 2

process 2

Operating System Concepts

19.26

Silberschatz, Galvin and Gagne 2002

Dynamic Storage-Allocation Problem

How to satisfy a request of size n from a list of free holes.


First-fit: Allocate the first hole that is big enough. Best-fit: Allocate the smallest hole that is big enough;

must search entire list, unless ordered by size. Produces the smallest leftover hole. Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole. First-fit and best-fit better than worst-fit in terms of speed and storage utilization.

Operating System Concepts

19.27

Silberschatz, Galvin and Gagne 2002

Fragmentation
External Fragmentation total memory space exists to

satisfy a request, but it is not contiguous. Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. Reduce external fragmentation by compaction
Shuffle memory contents to place all free memory together

in one large block. Compaction is possible only if relocation is dynamic, and is done at execution time. I/O problem Latch job in memory while it is involved in I/O. Do I/O only into OS buffers.

Operating System Concepts

19.28

Silberschatz, Galvin and Gagne 2002

File Concept
Contiguous logical address space
Types: Data numeric character binary Program

Operating System Concepts

19.29

Silberschatz, Galvin and Gagne 2002

File Structure
None - sequence of words, bytes
Simple record structure Lines Fixed length Variable length Complex Structures Formatted document Relocatable load file Can simulate last two with first method by inserting

appropriate control characters. Who decides:


Operating system Program

Operating System Concepts

19.30

Silberschatz, Galvin and Gagne 2002

File Attributes
Name only information kept in human-readable form.
Type needed for systems that support different types. Location pointer to file location on device. Size current file size. Protection controls who can do reading, writing,

executing. Time, date, and user identification data for protection, security, and usage monitoring. Information about files are kept in the directory structure, which is maintained on the disk.

Operating System Concepts

19.31

Silberschatz, Galvin and Gagne 2002

File Operations
Create
Write Read Reposition within file file seek Delete Truncate Open(Fi) search the directory structure on disk for entry

Fi, and move the content of entry to memory. Close (Fi) move the content of entry Fi in memory to directory structure on disk.

Operating System Concepts

19.32

Silberschatz, Galvin and Gagne 2002

File Types Name, Extension

Operating System Concepts

19.33

Silberschatz, Galvin and Gagne 2002

Example of Index and Relative Files

Operating System Concepts

19.34

Silberschatz, Galvin and Gagne 2002

Directory Structure
A collection of nodes containing information about all

files.
Directory

Files

F1

F2

F3

F4 Fn

Both the directory structure and the files reside on disk. Backups of these two structures are kept on tapes.
Operating System Concepts
19.35

Silberschatz, Galvin and Gagne 2002

Information in a Device Directory


Name
Type Address Current length Maximum length Date last accessed (for archival) Date last updated (for dump) Owner ID (who pays) Protection information (discuss later)

Operating System Concepts

19.36

Silberschatz, Galvin and Gagne 2002

Operations Performed on Directory


Search for a file
Create a file Delete a file List a directory Rename a file Traverse the file system

Operating System Concepts

19.37

Silberschatz, Galvin and Gagne 2002

Organize the Directory (Logically) to Obtain


Efficiency locating a file quickly.
Naming convenient to users. Two users can have same name for different files. The same file can have several different names. Grouping logical grouping of files by properties, (e.g.,

all Java programs, all games, )

Operating System Concepts

19.38

Silberschatz, Galvin and Gagne 2002

Single-Level Directory

A single directory for all users.

Naming problem Grouping problem

Operating System Concepts

19.39

Silberschatz, Galvin and Gagne 2002

Two-Level Directory
Separate directory for each user.

Path name Can have the same file name for different user Efficient searching No grouping capability

Operating System Concepts

19.40

Silberschatz, Galvin and Gagne 2002

Tree-Structured Directories

Operating System Concepts

19.41

Silberschatz, Galvin and Gagne 2002

File-System Structure
File structure Logical storage unit Collection of related information
File system resides on secondary storage (disks). File system organized into layers. File control block storage structure consisting of

information about a file.

Operating System Concepts

19.42

Silberschatz, Galvin and Gagne 2002

Layered File System

Operating System Concepts

19.43

Silberschatz, Galvin and Gagne 2002

A Typical File Control Block

Operating System Concepts

19.44

Silberschatz, Galvin and Gagne 2002

Allocation Methods
An allocation method refers to how disk blocks are

allocated for files:


Contiguous allocation Linked allocation Indexed allocation

Operating System Concepts

19.45

Silberschatz, Galvin and Gagne 2002

Contiguous Allocation

Each file occupies a set of contiguous blocks on the disk.


Simple only starting location (block #) and length

(number of blocks) are required.


Random access.
Wasteful of space (dynamic storage-allocation problem). Files cannot grow.

Operating System Concepts

19.46

Silberschatz, Galvin and Gagne 2002

Contiguous Allocation of Disk Space

Operating System Concepts

19.47

Silberschatz, Galvin and Gagne 2002

Linked Allocation
Each file is a linked list of disk blocks: blocks may be

scattered anywhere on the disk.


block =

pointer

Operating System Concepts

19.48

Silberschatz, Galvin and Gagne 2002

Linked Allocation (Cont.)

Simple need only starting address Free-space management system no waste of space No random access Mapping Q LA/511 R

Block to be accessed is the Qth block in the linked chain of blocks representing the file. Displacement into block = R + 1 File-allocation table (FAT) disk-space allocation used by MS-DOS and OS/2.
Silberschatz, Galvin and Gagne 2002

Operating System Concepts

19.49

Linked Allocation

Operating System Concepts

19.50

Silberschatz, Galvin and Gagne 2002

Indexed Allocation
Brings all pointers together into the index block.
Logical view.

index table

Operating System Concepts

19.51

Silberschatz, Galvin and Gagne 2002

Example of Indexed Allocation

Operating System Concepts

19.52

Silberschatz, Galvin and Gagne 2002

Indexed Allocation (Cont.)


Need index table

Random access
Dynamic access without external fragmentation, but have

overhead of index block. Mapping from logical to physical in a file of maximum size of 256K words and block size of 512 words. We need only 1 block for index table.
Q

LA/512
R

Q = displacement into index table R = displacement into block

Operating System Concepts

19.53

Silberschatz, Galvin and Gagne 2002

Schedulers (Cont.)
Short-term scheduler is invoked very frequently

(milliseconds) (must be fast). Long-term scheduler is invoked very infrequently (seconds, minutes) (may be slow). The long-term scheduler controls the degree of multiprogramming. Processes can be described as either:
I/O-bound process spends more time doing I/O than

computations, many short CPU bursts. CPU-bound process spends more time doing computations; few very long CPU bursts.

Operating System Concepts

19.54

Silberschatz, Galvin and Gagne 2002

System Calls
System calls provide the interface between a running

program and the operating system.


Generally available as assembly-language instructions. Languages defined to replace assembly language for

systems programming allow system calls to be made directly (e.g., C, C++) Three general methods are used to pass parameters

between a running program and the operating system.


Pass parameters in registers. Store the parameters in a table in memory, and the table

address is passed as a parameter in a register. Push (store) the parameters onto the stack by the program, and pop off the stack by operating system.

Operating System Concepts

19.55

Silberschatz, Galvin and Gagne 2002

Security
The Security Problem
Authentication Program Threats System Threats Securing Systems Intrusion Detection Encryption Windows NT

Operating System Concepts

19.56

Silberschatz, Galvin and Gagne 2002

The Security Problem


Security must consider external environment of the

system, and protect it from:


unauthorized access. malicious modification or destruction accidental introduction of inconsistency.

Easier to protect against accidental than malicious

misuse.

Operating System Concepts

19.57

Silberschatz, Galvin and Gagne 2002

Authentication
User identity most often established through passwords,

can be considered a special case of either keys or capabilities.


Passwords must be kept secret. Frequent change of passwords. Use of non-guessable passwords. Log all invalid access attempts.

Passwords may also either be encrypted or allowed to be

used only once.

Operating System Concepts

19.58

Silberschatz, Galvin and Gagne 2002

Program Threats
Trojan Horse Code segment that misuses its environment. Exploits mechanisms for allowing programs written by users to be executed by other users.
Trap Door Specific user identifier or password that circumvents normal security procedures. Could be included in a compiler. Stack and Buffer Overflow Exploits a bug in a program (overflow either the stack or memory buffers.)

Operating System Concepts

19.59

Silberschatz, Galvin and Gagne 2002

System Threats
Worms use spawn mechanism; standalone program
Internet worm Exploited UNIX networking features (remote access) and bugs in finger and sendmail programs. Grappling hook program uploaded main worm program. Viruses fragment of code embedded in a legitimate program. Mainly effect microcomputer systems. Downloading viral programs from public bulletin boards or exchanging floppy disks containing an infection. Safe computing. Denial of Service Overload the targeted computer preventing it from doing any sueful work.

Operating System Concepts

19.60

Silberschatz, Galvin and Gagne 2002

Threat Monitoring
Check for suspicious patterns of activity i.e., several

incorrect password attempts may signal password guessing. Audit log records the time, user, and type of all accesses to an object; useful for recovery from a violation and developing better security measures. Scan the system periodically for security holes; done when the computer is relatively unused.

Operating System Concepts

19.61

Silberschatz, Galvin and Gagne 2002

Threat Monitoring (Cont.)


Check for: Short or easy-to-guess passwords Unauthorized set-uid programs Unauthorized programs in system directories Unexpected long-running processes Improper directory protections Improper protections on system data files Dangerous entries in the program search path (Trojan horse) Changes to system programs: monitor checksum values

Operating System Concepts

19.62

Silberschatz, Galvin and Gagne 2002

FireWall
A firewall is placed between trusted and untrusted hosts.
The firewall limits network access between these two

security domains.

Operating System Concepts

19.63

Silberschatz, Galvin and Gagne 2002

Intrusion Detection
Detect attempts to intrude into computer systems.
Detection methods: Auditing and logging. Tripwire (UNIX software that checks if certain files and directories have been altered I.e. password files) System call monitoring

Operating System Concepts

19.64

Silberschatz, Galvin and Gagne 2002

Encryption
Encrypt clear text into cipher text.
Properties of good encryption technique: Relatively simple for authorized users to incrypt and decrypt data. Encryption scheme depends not on the secrecy of the algorithm but on a parameter of the algorithm called the encryption key. Extremely difficult for an intruder to determine the encryption key. Data Encryption Standard substitutes characters and

rearranges their order on the basis of an encryption key provided to authorized users via a secure mechanism. Scheme only as secure as the mechanism.

Operating System Concepts

19.65

Silberschatz, Galvin and Gagne 2002

Encryption (Cont.)
Public-key encryption based on each user having two

keys:
public key published key used to encrypt data. private key key known only to individual user used to

decrypt data.

Must be an encryption scheme that can be made public

without making it easy to figure out the decryption scheme.


Efficient algorithm for testing whether or not a number is

prime. No efficient algorithm is know for finding the prime factors of a number.

Operating System Concepts

19.66

Silberschatz, Galvin and Gagne 2002

Encryption Example - SSL


SSL Secure Socket Layer
Cryptographic protocol that limits two computers to only

exchange messages with each other.


Used between web servers and browsers for secure

communication (credit card numbers)


The server is verified with a certificate. Communication between each computers uses symmetric

key cryptography.

Operating System Concepts

19.67

Silberschatz, Galvin and Gagne 2002

Windows NT Example
Configurable security allows policies ranging from D to C2.
Security is based on user accounts where each user has a

security ID.
Uses a subject model to ensure access security. A subject

tracks and manages permissions for each program that a user runs.
Each object in Windows NT has a security attribute defined by a

security descriptor. For example, a file has a security descriptor that indicates the access permissions for all users.

Operating System Concepts

19.68

Silberschatz, Galvin and Gagne 2002

S-ar putea să vă placă și