Review: Operating System

Download Report

Transcript Review: Operating System

Review: Operating System
Manages all system resources
ALU
Memory
I/O
Files
Objectives:
Security
Efficiency
Convenience
What is a process?
• Any running program including its context and
environment:
–
–
–
–
Register content
Memory content and address space
PC
State (example: waiting for I/O)
Process Management
• Why process management?
– There is only one (or a limited number of) CPU per
computer, but most of the time many programs run at
the “same” time
– Multi user systems such as sales, debit or eureka
(UNIX machines of Stern)
– All modern computer support multitasking via time
slicing
– List of current processes
• Task list on PC after CTR-Alt-Del
• top command under UNIX
Process abstraction and context
• Any process feels as if he was the only one
running on the machine, he does not need to
know anything about any other process (unless
related)
• But a processor has a limited amount of physical
resources and every process on the machine has
its own set of registers. Solution: save and restore
hardware state on a context switch. Save the state
in Process Control Block (PCB)
Process Control Block
• All information that is associated with a process
–
–
–
–
–
–
Process state (new, ready, waiting …)
PC (Program Counter) how far got the execution
CPU Register content
Memory management information
I/O status
Some accounting (open files …)
• All this information has to be updated whenever
the process changes state: Overhead!
Historical Difference UNIX, DOS
• Uniprogramming: one process at a time
• Multiprogramming: multiple processes
• DOS was originally uniprogramming
– One key problem with DOS is that there is no
memory protection - one program may write the
memory of another program, causing weird bugs.
• Unix plus all currently envisioned new operating
systems allow system to separate out activities
cleanly
Process Creation
• Parent processes create child processes, which in
turn create further child processes
• Resource sharing
– degree of sharing can vary from all to none
• Execution
– concurrently
– parent waits for child to terminate
– example in UNIX: call child with & option keeps the
parent active
Process Termination
• User logs off
• Quit an application
– User interaction
– Time limit exceeded
• Process finished: Normal completion
• Error
– Memory unavailable
– Arithmetic error
– Security error: Memory or file
Process Termination
•
•
•
•
•
I/O Failure
Invalid instruction (you tried to execute data)
Operating system intervention (e.g. deadlock)
Parent terminates (shell logout)
Parent requests termination(kill)
Process States
• During Execution a process changes state
– new: The process is being created
• User calls a program
• Some program starts another process
–
–
–
–
running: Instructions are executed
waiting: The process is waiting for an event to occur
ready: The process is waiting to be executed
terminated: The process has finished execution
Diagram of Process States
new
exit
admitted
terminated
interrupt
ready
running
scheduler
I/O or event completion
waiting
I/O or event wait
Process States Example
Memory
CPU Switch from Process to Process
P0
executing
OS
P1
Interrupt
Save state in PCB0
idle
Load state from PCB1
idle
Interrupt
executing
Save state in PCB1
Load state in PCB0
executing
idle
Interrupts
• Two types: Hardware and Software
• Hardware interrupts are generated by a physical device
• Software generated by OS for instance after timeout of
running process
• Interrupt register/bus that communicates interrupt to
the control unit of CPU
• Different Levels
– depending on the priority of the current process,
lower level interrupts can be ignored
– hardware have usually higher priority than software
interrupts
Context Switch
• When CPU switches to another process, the
system must save the state of the old process and
load the saved state for the new process
• Context switch time is overhead during which the
system does no useful work
• Overhead depends on hardware support
• Question: You have 6 big job to run on a 2
processor machine. What is the optimal strategy
to start them?
Scheduling Objectives
• Fairness
– Give equal and fair access to all processes
• Responsiveness
– Discriminate between different classes of jobs
• Efficiency
– Maximize throughput
– Minimize response time
– Accommodate as many uses as possible
Process Scheduling Queues
• Job queue - all processes in the system
• Ready queue - all processes residing in main
memory ready and waiting to execute
• Device queue - set of processes waiting for an
I/O device
• Process migration between various queues
Two Queues
Appendix: UNIX Commands
• ps: show all processes that were started from this
shell
– ps -u username : all processes started by user
• top: show all processes running on the computer
• kill id : Stop running process with id
• nohup: make process immune to high level
interrupts
• nice +int process: change the priority of a process
• man command: get information about command