Transcript Document

Unit 4: Processes, Threads & Deadlocks
June 2012
Kaplan University
1





Readings
Discussion Questions
Assignments
Lecture on Processes, Threads & Deadlocks
Prepping your computer for simulations
Kaplan University
2

Textbook Reading
◦
◦
◦
◦



Chapter 3 – Process Description & Control
Chapter 4 – Threads
Chapter 6 – Concurrency: Deadlocks & Starvation
Start with chapter summaries first!
Web Articles Reading
1 Discussion Question
4 page essay (due Tuesday)
Kaplan University
3
o
o
o
Deadlocks are a dreaded state for modern
computer systems and do take place quite
often.
For deadlocks to happen, four conditions
must be met. What are they? Explain.
Note: Your response should only list one
condition. The responses to follow should
list conditions not yet discussed.
Kaplan University
4



The project for this Unit is a “hands-on” one. You are required to
submit screenshots of both your Linux and windows task
managers.
You will explore the tools available for Linux and Windows for
examining processes and threads and write a report in the usual
APA format.
For Windows:
o Download the utility “Process Monitor” in this link and run it to aid you
understand more about processes running on your Windows OS
o http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
o Run the utility on your Windows computer. Capture several
screenshots of the interface and processes running on your PC.
Kaplan University
5

For Linux:
o Logon to your installed distribution, open a terminal
window also called Xterm, and run the command “top”
without the quotation marks followed by the return
key. For better results with the top command, use the
“man”pages to see all available switches for you to use
with top.
o To do that, at theconsole type: man top
“man top” is short for “manual on the top command”.
o You will get several options and switches, read
through them and use what you deem needed. To quit
the man pages, simply type the letter “q”.
Kaplan University
6



Write a four-page detailed report on what you observed
and relate it to what you learned about processes, threads,
deadlocks, preventions, avoidance, and detection.
Be sure to submit a screen shot for each task manager
output for Linux and Windows. To make screenshots,
Windows users just need to press the "Print Screen" key.
Mac users press Command+Shift+3.
Your paper should include at least four pages of content.
Note that your paper will be longer than four pages as it
will have a title page, table of contents, and a reference
page in addition to the actual content pages required.
Kaplan University
7




10 pts – The content of the paper is clear and demonstrates
the student’s understanding of the topics.
15 pts – Student explained the concept of processes/threads
in modern computing and correlated them to what was
observed in Process Monitor & Top
10 pts – Student provided screenshots for Process Monitor &
Top (NOTE: You must use Process Monitor not Task Manager)
15 pts – Student compared and explained the concept of
deadlock & related topics (avoidance, preventions, &
detection).
Kaplan University
8
Kaplan University
9



In your own words (based on your reading
and research for this week):
Define “process”
Describe how an operating system uses
processes
Kaplan University
10

A program in execution

An instance of a program running on a
computer

The entity that can be assigned to and
executed on a processor

A unit of activity characterized by the
execution of a sequence of instructions, a
current state, and an associated set of system
instructions
Kaplan University
11

A process includes:
◦ Program code (possibly shared)
◦ A set of data
◦ A number of attributes describing the state of the
process
Kaplan University
12

While the process is running it has a number
of elements including
◦
◦
◦
◦
◦
◦
◦
◦
Identifier
State
Priority
Program counter
Memory pointers
Context data
I/O status information
Accounting information
Kaplan University
13



Contains the process elements
Created and managed
by the operating system
Allows support for
multiple processes
Kaplan University
14

Process may be in one of two states
◦ Running
◦ Not-running
Kaplan University
15
Processes are moved by the dispatcher of the OS
to the CPU then back to the queue until the task is
completed
Kaplan University
16
Kaplan University
17


For the OS is to manage processes and
resources, it must have information about the
current status of each process and resource.
Tables are constructed for each entity the
operating system manages
Kaplan University
18
Kaplan University
19
What is a Thread?
Kaplan University
20

Processes have two characteristics:
◦ Resource ownership
Process includes a virtual address space to hold the
process image
◦ Scheduling/execution
Follows an execution path that may be interleaved
with other processes

These two characteristics are treated
independently by the operating system
Kaplan University
21



The unit of dispatching is referred to as a
thread or lightweight process
The unit of resource ownership is referred to
as a process or task
One way to view a thread is as an
independent program counter operating
within a process.
Kaplan University
22
Kaplan University
23




Takes less time to create a new thread than a
process
Less time to terminate a thread than a
process
Switching between two threads takes less
time that switching processes
Threads can communicate with each other
without invoking the kernel
Kaplan University
24

Differences between different Operating
Systems support of processes include:
How processes are named
Whether threads are provided
How processes are represented
How process resources are protected
What mechanisms are used for inter-process
communication and synchronization
◦ How processes are related to each other
◦
◦
◦
◦
◦
Kaplan University
25

Processes and services provided by the
Windows Kernel are relatively simple and
general purpose

Implemented as objects

An executable process may contain one or
more threads

Both processes and thread objects have builtin synchronization capabilities
Kaplan University
26
Kaplan University
27


A process, or task, in Linux is represented by
a task_struct data structure
This contains a number of categories
including:
◦
◦
◦
◦
◦
State
Scheduling information
Identifiers
Interprocess communication
And others
Kaplan University
28
Kaplan University
29

In your own words, describe two differences
between Windows and Linux, in terms of
processes and threads.
Kaplan University
30
What is meant by the term
“deadlock”?
Kaplan University
31

A set of processes is deadlocked when each
process in the set is blocked awaiting an
event that can only be triggered by another
blocked process in the set
◦ Typically involves processes competing for the
same set of resources

No efficient solution for the general case
Kaplan University
32
I need
quad C
and B
I need
quad B
and C
I need
quad A
and B
I need
quad D
and A
Kaplan University
33
HALT until
D is free
HALT until
C is free
HALT until
B is free
HALT until
A is free
Kaplan University
34




Mutual exclusion
◦ Only one process may use a resource at a time
Hold-and-wait
◦ A process may hold allocated resources while awaiting
assignment of others
No pre-emption
◦ No resource can be forcibly removed from a process
holding it
Circular Wait
◦ Each process is waiting for a resource held by the next
process in the chain
Kaplan University
35

Three general approaches exist for dealing
with deadlock.
◦ Prevent Deadlock
 Guarantee that one of the 4 conditions does not occur
◦ Avoid Deadlock
 Gather info from processes and require processes to
declare max number of resources it might need
◦ Detect Deadlock
 Check for possible deadline by checking for resources
and stop processes that might cause deadlock
Kaplan University
36




Write a four-page detailed report on what you observed and
relate it to what you learned about processes, threads,
deadlocks, preventions, avoidance, and detection.
Be sure to submit a screen shot for each task manager output
for Linux and Windows. To make screenshots, Windows users
just need to press the "Print Screen" key. Mac users press
Command+Shift+3.
Your paper should include at least four pages of content.
Note that your paper will be longer than four pages as it will
have a title page, table of contents, and a reference page in
addition to the actual content pages required.
Use APA style.
Kaplan University
37

Textbook

Topic Notes on Deadlock
http://www.williamstallings.com/OS/Animation/An
imations.html
http://courses.teresco.org/cs322_s08/notes/deadl
ock.pdf
Kaplan University
38

Pam Van Hook
◦ Email: [email protected]
◦ Email: [email protected]
Kaplan University
39