CSE 7343/5343, Spring 2003
Topic 2: Processes and Threads
Prof. Jeff Tian, CSE/SoE/SMU, Dallas, TX 75275
tian@engr.smu.edu; www.engr.smu.edu/~tian/class/7343.03s
- Dates: 1/21-30/03.
- Reading: Ch4 (processes) and Ch5 (threads).
Process concept
- programs, tasks, jobs, and processes
- liveness property
- activity, in-execution
- multiprogramming assumption
- historical perspective
- hardware/equipment perspective
- processes in multi-user to single-user system
- task characteristic assumptions
- what make up a process?
- program in execution, but what is needed for execution?
program + dynamic contents + resources
-
operate upon, individual operations?
two types: I/O, computation (arithmetic calculation and logical decisions)
-
overall sequence = ?
bursty mode: CPU-burst vs I/O burst
-
requested resource available?
yes, execution (swap/switch in)
no, waiting at buffer/queue/etc.
I/O operations as a special waiting state
-
dynamic state = ?
pointers to program/stack/data, registers
save/restore to ensure progress or to avoided repeated execution
-
dynamic support by system = ?
representing/tracking/handling processes, etc., later
Process states and PCBs
- types of dynamic states => process states
- Fig. 4.1 (p.97)
- new, ready, running, waiting, terminated
- linkage between the states
- "waiting" is more like a "mega-state"
- example of multiple waiting queues
- different waiting conditions/queues
- physical as well as logical resources/locks/conditions
- different devices
- operating at the devices/conditions/resources
- pure "waiting"
- disciplines => process management
- process info. in your OS = PCB
- information in PCB, Fig. 4.2 (p.97)
all the information make it run
state, IP/PC, registers, other info (pp. 90-91)
in PCB and related locations (stacks etc)
- identification and PCB organization:
PID, ptr, table entry, etc.
- dynamic contents:
PC/IP, register, state
- resource management information:
CPU, memory, I/O, account, etc.
- handling PCBs: process tables, queues etc.
discussion in connection with processing handling, later
- PCB contents => switching processes
- organizing the PCBs
- process tables
- linked lists
- example in book
- uniform PCBs vs non-uniform
- use of pointers
- efficiency/overhead/flexibility in maintaining PCBs
Processes handling and context switching
- major operations involved in handling processes
- creating processes and PCBs
- context switching
- CPU and I/O operations
- termination and cleanup
- details later
- general assumptions about processes
- alternating CPU and I/O bursts
related terms: CPU-bound vs. I/O-bound processes
- effective utilization of system resources through processes
related: job mixing/sequencing
- dependencies/communication among processes
- other general issues, later
- threads of executions within processes, more late
- bottom-up: context switching, queues, start/end
- context switching
- use information from PCB
- use associated memory, stack, etc.
- switch out: save information
- switch in: restore information
- key:
to keep from repeating computation/execution that has been done already.
- example use PCB only for 2 processes Fig.4.3 (p.98)
- example use PCB and stack:
more flexibility
communication, command line parameters, etc.
- implementation overhead of context switching
- hardware/OS support
- multiple register sets, fast switch
- copy to/from memory
- possible use of cache
- directly at PCB or stack space
- overhead implications on scheduling:
CPU scheduling
memory management
memory hierarchy (register, cache, etc.)
Process scheduling
- process scheduling/queuing
- CPU queue: "ready" queue
- I/O queues
- other queues (IPC, process coordination.)
- queuing discipline and implementation
- priority
- timing
- pre-emption (time quantum expires)
- implementation:
data structure: queue
head vs head&tail
example queues in book Fig 4.4 (p.100)
example queuing diagram for process scheduling Fig 4.5 (p.101)
general queues: buffer and selection
- scheduling hierarchy
- short-term: above
- long-term: admit/remove (creation/termination below)
- sometimes, medium-term: temporary suspend
swap in/out (medium scheduler) in Fig. 4.6 (p.102)
- focus: short-/long-term
- process creation/termination
- implicit from user: start/finish a program
- explicit from processes:
fork/join vs parbegin/parend (or cobegin/coend)
- difference in interpretations
- process hierarchy (book)
UNIX example, Fig 4.7 (p.104)
- process modeling (dynamic models)
- idea of transaction flow (testing) model
- implementation concerns
- PCB and other initial allocation
too many processes?
long term scheduling
- normal termination:
cleanup, release resources, etc.
- abnormal termination:
to break deadlocks
because of parent process terminated -- cascading termination
failures and failure-chaining terminating
additional issues in handling abnormal terminations
- resources: partitioning vs. request new
- parents active? variations above
- multiple/separate code/program?
- system calls
- UNIX: fork(), wait(), exit()
Processes communication/coordination/etc.
- cooperating processes
- independent vs. cooperating
- independent: cannot affect or be affected by other processes
- no "true" independence under multi-programming environment
- cooperating through shared resources or messages (IPC)
- why cooperating:
- information sharing: access to code, data, (partial) results
examples: parent/children, reader/writer, consumer/producer
- computation speedup: parallel execution
necessary condition: dependency analysis and parallel resources)
related: better utilization of system resources
- modularity: common components, divide-and-conquer, reuse paradigm
handling large-sized/complex tasks,
hardware/software ideas: RISC, structured/OO design
- convenience: no dedicated attention/resource (parallelism)
example: editing/printing/compiling without just waiting
- direct sharing vs message passing
- compare to tightly-coupled with distributed systems
- IPC: interprocess communication
- physical/logical link for communication
- layered approach: ISO/OSI 7 layers
- different communication protocols
- direct vs indirect (naming?)
- synchronous vs asynchronous
blocking/handshake or not (port, mbox)
- symmetric?
- buffering/queuing
- message size?
- case study in book (IPC in client-server systems)
- more to come in distributed systems/OS
Thread concept and example
- threads vs. processes
- example: Fig 5.1 (p.130)
- lightweight vs. heavyweight
- allows for better CPU utilization
- shared: code/data section, OS resources
- different: TID, PC/IP, register set, and stack
- browser example: display/loading/interfacing
- multiple sets of registers to allow for fast context switching
- main benefit of threads
- responsiveness
avoid overall blocking/waiting,
urgency vs. speed,
response time for interactive applications
- resource sharing and economy
implementation efficiency for threads
e.g., Solaris, 30 times difference
- utilizing multiprocessor architecture
- overall: finer-grain utilization improvement
- enabling factors:
- faster/more powerful processors
multiple sets of registers or processors
otherwise, everything slowed down
- multi-threaded applications
parallelism, based dependency analysis
- thread models and implementations
- user and kernel threads
- done at user/kernel space without/with OS support
- mapping from user to kernel threads:
N-1, 1-1, N-M (Fig. 5.2, 5.3, 5.4, pp.133-134)
- Solaris example in book
read to understand the basic concepts
- Windows, Linux and Java threads in book too
- thread management:
similar to but simpler than (subset of) process management
Prepared by Jeff Tian
(tian@engr.smu.edu).
Last update Jan. 30, 2003.