Title: Program
1Program
- Whats a program?
- Is a static entity. Only exist as an idea, on
paper, or as a file.
2Processes
- Process An abstraction of a running program.
- Multiprogramming allows for the processor to
switch between several different processes in
memory. - Processor may only run each program a fraction of
a second
3Pseudoparallelism
- Processor switches between each program so fast
it gives the appearance of programs running in
parallel. - This is in contrast to true parallelism which
requires a system with more than 1 CPU.
4Thinking in Parallel
- Very hard for humans to do
- We have a conceptual model called the sequential
process or just process. - Associated with a process are its code, input,
output and state.
5Consider 3 processes
- How do we maintain where each process is in its
execution as each one is switched out of running
on the CPU? - Each process has a logical PC that is saved with
the process - So, when a particular process is going to execute
on the CPU what happens with the logical PC? - Loaded into the Physical PC
6Four Events that can trigger process creation
- System Initialization
- Execution of a process creation system call by a
running process - A user request to create a new process.
- Initiation of a batch process.
7Types of Processes
- Foreground
- Processes that interact with the user and perform
work for them - Background
- Not associated with a user, but perform some type
of specific function for the system (accepting
incoming email)
8After a process has performed its job
- It is terminated by the following methods
- Normal exit (voluntary)
- Error exit (voluntary Usually User Causes)
- Fatal error (involuntary Usually Process
Causes) - Killed by another process (involuntary)
9Process States
- Running A process that is executing on a CPU.
If the system has n CPUs, at most n processes may
be in the running state. - Ready A process that is not allocated to the
CPU but is ready to run. A ready process could
execute if allocated to a CPU.
10Process States (cont.)
- Blocked A process that is waiting for some
event to occur before it can continue executing.
This event is often the completion of an I/O
operation. - Do not confuse Blocked and Ready Processes
11Process State (cont)
- Terminated process that has halted its
execution but a record of the process is still
maintained by the OS. This record may be useful
to other processes.
12Process State Diagram
Terminated
Exit
Running
Scheduler decides another process should run
Process blocks waiting for some external event
Scheduler decides a process should run
Blocked
Ready
Once a process is created It is placed in the
ready state
Process is unblocked once external event occurs
New
13So, how do we keep track of information about a
process?
- Process Control Block (PCB) Just an array of
structures with 1 entry per process - A PCB entry contains the PC, SP, memory
allocation, status of its open files, scheduling
info, anything to restore the process when
switching states - Nucleus Plus uses a PCBs but calls them another
name - Page 80 in the book has a more complete list of
fields often found in a PCB
14Two ways of looking at processes
- Resource Ownership
- Program (code), data, and other attributes
defined in the PCB - May be allocated other resources files, I/O
devices, main memory - Scheduling/execution
- Path of execution through a program
- Also a state (ready, running, blocked, etc)
15Two ways of looking at processes
- We can separate these two concepts and many
operating systems do separate these concepts - Unit of dispatching/scheduling is called a thread
- Unit of resource ownership is referred to as a
process
16Different OS have different levels of thread
support
Instruction Trace
1 process, 1 thread - MSDOS
1 process, Multiple threads, Java RTE
Multiple process, 1 thread - UNIX
Multiple process, Multiple threads, Windows,
Solaris, OS/2
17Processes vs. Threads
- Each process has its own address space
containing program text and data along with other
resources. - A process also has a thread of execution, so
threads are a part of a particular process. - Each thread has its own PC, registers, stack,
and state just like a process
18Processes vs. Threads (cont.)
- But threads allow us to use the same
- Address space
- Global Variables
- Open Files
- Obviously we do not want to create separate
processes (more overhead) if these resources can
be shared.
19Benefits of using Threads
- Ability of multithreaded entities to share
address space and data. - Easier to create and destroy in comparison to
processes which have resources. - Improved Performance when substantial computing
power is available and substantial I/O - Useful for multiprocessor systems
20Thread Implementation User Level
- User-level threads perform threading operations
in user space - Threads are created by runtime libraries that
cannot execute privileged instructions or access
kernel primitives directly
21Thread Implementation User Level
- User-level thread implementation
- Many-to-one thread mappings
- Operating system maps all threads in a
multithreaded process to single execution context - Advantages
- User-level libraries can schedule its threads to
optimize performance - Synchronization performed outside kernel, avoids
context switches - More portable Do not need OS support for
threads - Disadvantage
- Kernel views a multithreaded process as a single
thread of control - Can lead to suboptimal performance if a thread
issues I/O - Cannot be scheduled on multiple processors at
once
22Thread Implementation Kernel Level
- Kernel-level threads attempt to address the
limitations of user-level threads by mapping each
thread to its own execution context - Kernel-level threads provide a one-to-one thread
mapping - Advantages Increased scalability, interactivity,
and throughput - Disadvantages Overhead due to context switching
and reduced portability due to OS-specific APIs - Kernel-level threads are not always the optimal
solution for multithreaded applications