Module 4: Processes

Download Report

Transcript Module 4: Processes

Operating Systems
Lecture 7
OS System Structure
Processes
Operating System Concepts
4.1
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Types of OS structure
The design of operating systems has evolved over time.
We can roughly divide them into the following categories:
1. Monolithic systems (1st operating systems).
2. Modular systems (E.g. early UNIX)
3. Hierarchical layered systems (e.g. OS/2)
4. Microkernel systems (e.g. Mach)
5. Virtual Machines
Operating System Concepts
4.2
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
From monolithic to modular
Monolithic systems:
 No structure to speak of.
 As the OS grows, the complexity becomes overwhelming.
 Example: OS/360 version 1
 created by 5000 programmers over 5 years.
 In 1964, had over 1 million lines of code.
Modular systems:
 Divide OS into modules.
 Example: Original UNIX had 2 modules.
 System programs (e.g. emacs, compiler)
 The kernel (HUGE!)--file system, CPU scheduling,
memory management, etc.
 Problem: Kernel so big and complex that it was hard to work
with and extend.
Operating System Concepts
4.3
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Layered Systems
Hierarchical Layered Systems:
 Bottom layer: Hardware
 Top layer: User interface
 Easier to debug (can work on single layer)
 Goal: Allow one layer to change without needing to change
other layers.
 Example: OS/2, some newer versions of UNIX
 Problems:
 Division of layers can be difficult to define.
 Efficiency: Each layer adds overhead.
 Modification still proved difficult. Many interfaces exist
between two layers.
Operating System Concepts
4.4
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Microkernels
Microkernels:
 Define kernel as small as possible.
 Kernel is the ONLY code that is machine/device dependent.
 Implement the rest of the OS as user processes.
 Uses client-server communication model (message passing).
 Advantages: (will discuss in class)
 Modularity (Easy to modify modules)
 Extensibility (Can easily add new functions--user processes)
 Flexibility (Can remove functions that are not needed)
 Portability (Only the small kernel has hardware specific code)
 Distributed System support (Message passing can generalize
to network communications)
 Object oriented (A good design).
 Disadvantages: (will discuss in class)
 Performance: create/send receive message takes longer than a
system call. Efficiency still a problem.
Operating System Concepts
4.5
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Virtual Machines
Virtual Machines:
 Provides software interface identical to underlying bare hardware.
 Virtual CPU, Virtual Device drivers, Virtual memory, etc.
 Each process has its own virtual machine
 Implementation provides interface between virtual machine and real
machine.
 Physical resources divided up between the virtual machines (e.g.
minidisks).
 Advantages: (will discuss in class)
 Security (no process has direct access to system resources.)
 System development (Can use virtual machine to test new OS)
 System compatibility. Can run Windows on Virtual PC on Mac.
 Java runs on Java virtual machine--cross platform.
 Disadvantage: (will discuss in class)
 Speed: Each instruction is interpreted. This is slower than a
direct system call.
Operating System Concepts
4.6
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Virtual Machine Diagram
Non-virtual Machine
Operating System Concepts
Virtual Machine
4.7
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Java Virtual Machine
 Compiled Java programs are
platform-neutral bytecodes
executed by a Java Virtual
Machine (JVM).
 JVM consists of
- class loader
- class verifier
- runtime interpreter
 Just-In-Time (JIT) compilers
increase performance
Operating System Concepts
4.8
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Processes
 Process – a program in execution;
 A process includes: (will discuss in class)
 program code (text section)
 program counter
 contents of registers
 Process stack (temporary data, e.g. method
parameters, etc.)
 data section (eg. global variables).
Operating System Concepts
4.9
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
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
4.10
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Diagram of Process State
We will create this in class.
Operating System Concepts
4.11
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Process Control Block (PCB)
Information associated with each process is stored in PCB.
 Process state
 new, running, etc.
 Program counter
 address of next instruction to be executed
 CPU registers
 E.g. accumulator, stack pointers, general purpose registers.
 CPU scheduling information
 Process priority, elapsed time, etc.
 Memory-management information
 E.g. base and limit registers
 Accounting information
 E.g. amount of CPU time used, account number, etc.
 I/O status information
 I/O devices allocated, list of open files, etc.
Operating System Concepts
4.12
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Process Control Block (PCB)
The PCB is constructed at process
creation.
PCB includes a pointer to be used
in lists (queues) of PCBs.
The PCB is used to save
information about a process when
switched out of CPU.
Operating System Concepts
4.13
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
CPU Switch From Process to Process
We will diagram this in class.
Operating System Concepts
4.14
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Process Scheduling Queues
 As processes move between states, they join other
processes waiting for particular resources (e.g. CPU time,
I/O device, etc.)
 The Operating System keeps lists of processes in
queues (linked lists).
 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.
 Process state list -- list of processes in each state
 Event queues -- list of processes waiting for an event.
Operating System Concepts
4.15
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Ready Queue And Various I/O Device Queues
Operating System Concepts
4.16
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005
Representation of Process Scheduling
Operating System Concepts
4.17
Silberschatz, Galvin and Gagne 2002
Modified for CSCI 399, Royden, 2005