What Is An Operating System?
A modern computer consists of:
• One or more processors
• Main memory
• Disks
• Printers
• Various input/output devices
Managing all these components requires a layer
of
software – the operating system
Figure . Where the operating system fits in.
The Operating System as an Extended
Machine
Operating systems turn ugly hardware into
beautiful
abstractions.
The Operating System as a Resource
Manager
• Allow multiple programs to run at the same
time
• Manage and protect memory, I/O devices, and
other resources
• Includes multiplexing (sharing) resources in
two
different ways:
• In time
• In space
The Process Model
• Process: an abstraction of a running program.
• All runnable software is organized into a
number of sequential processes.
• Each process has its own flow of control (i.e.
program counter, registers and variables).
• In a multiprogramming environment, processes
switch back and forth.
• No built-in assumption about timing in
programs (use interrupts instead).
The Process Model
Figure 2-1. (a) Multiprogramming of four programs. (b)
Conceptual model of four independent, sequential
processes. (c) Only
one program is active at once.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Process Creation
Events which cause process creation:
• System initialization.
• Execution of a process creation system
call by a running process (e.g., fork() in
unix).
• A user request to create a new process
(shell command or click an icon).
• Initiation of a batch job.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Process Termination
Events which cause process termination:
• Normal exit (voluntary).
• Error exit (voluntary).
• Fatal error (involuntary).
• Killed by another process (involuntary).
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Process Hierarchies
• Parent creates a child process, child
processes can create its own child process
• Forms a hierarchy
– UNIX calls this a "process group"
• Windows has no concept of process hierarchy
– all processes are created equal
Process States
Three state model:
1. Running: using CPU currently.
2. Blocked: unable to run until some external event
(e.g. I/O completes) happens.
3. Ready: runnable, temporarily stopped to let another
process run.
Four possible transitions:
1. Process blocked for input.
2. Scheduler picks another process.
3. Scheduler picks this process.
4. Input becomes available.
Process States
Figure 2-2. A process can be in running, blocked, or
ready state.
Transitions between these states are as
shown.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Process States
What happens when all processes in memory
are blocked for I/O?
• Swapping: move a process from memory to
disk (suspend) and bring another process on disk
to memory.
• Five state model, add two more states:
1. Blocked/Suspend: the process is in
secondary memory and waiting an event.
2. Ready/Suspend: the process is in secondary
memory but is available for execution as soon as
it is loaded into memory.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementation of Processes (2)
Figure 2-4. Some of the fields of a typical process table
entry.
Thread Usage (1)
Figure 2-7. A word processor with three threads.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Thread Usage (2)
Figure 2-8. A multithreaded Web server.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Thread Usage
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Classical Thread Model (1)
Figure 2-11. (a) Three processes each with one thread.
(b) One
process with three threads.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Classical Thread Model (2)
Figure 2-12. The first column lists some items shared
by all threads in a process. The second one lists some
items private
to each thread.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The Classical Thread Model (3)
Figure 2-13. Each thread has its own stack.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
POSIX Threads (1)
Figure 2-14. Some of the Pthreads function calls.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementing Threads in User
Space
Figure 2-16. (a) A user-level threads package. (b) A
threads package managed by the kernel.
Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Hybrid Implementations
Figure 2-17. Multiplexing user-level
threads onto kernel-level
threads.