Title: (Process Management)
1?2? ???? ??(Process Management)
- ???? ???? ????, the unit of work(???? ????)
- CPU time, memory, files, I/O devices -gt ??
- 1. user process(??? ????) - user code ??
- 2. system process(??? ????) - system code ??
- ???? ??
- user process(??? ????)? system process(??? ?????
??? ?? - ???? ????
- ?????? ??? ?? ??
- ?????? ?? ??
- ?????? ????(deadlock)??
2?4? ????(Processes)
- ?? 1 program ?? -gt ??? multiple program? ?? ??
4.1 ???? ??(Process Concept)
- ??
- job batch system
- task time-sharing system
- process
- ????(The Process)
- ???? ?? ?? ??(Current activity)
- PC(Program Counter)
- ???? ?
- ??(stack) -????, ????, ????, ???? ?
- ??? ??(data section)- ????
- ???? ??(Process State)
- ??(new)
- ??(running) - CPU? ??
- ??(waiting) - I/O??? signal ???
- ??(ready) - Processor? ?? ??? ?
- ??(terminated)
- p99 ?? 4.1
34.1 ???? ??(Process Concept)
cont.
- ???? ?? ??(Process Control Block)
- ? ????? PCB? ???
- PCB p100 ?? 4.2
- ???? ?? new, ready, running, waiting, halted
- ???? ??? next instruction? ??
- CPU????? accumulator, index register, stack
pointers, ?? registers, condition-code - CPU??? ?? priority, pointers to scheduling
queues - ??? ?? ?? base and limit registers, page tables,
segment tables - ?? ?? time used, time limits, account numbers,
job, process - ??? ?? ?? I/O devices list allocated to the
process, list of open files
44.2 ???? ????(Process Scheduling)
- ???? ?(Scheduling Queues)
- p102 ?? 4.4
- job queue(?? ?) memory ?? ???? ?(disk??)
- ready queue(?? ?) CPU? ?? ???? ?
- device queue(?? ?) ??? ???? ?
- queueing diagram(?? ??) p103 ?? 4.5
- ????(Schedulers)
- ?? ????(long-term scheduler, job scheduler)
- pool -gt memory(degree of multiprogramming)
- ?? ????(short-term scheduler, CPU scheduler)
- CPU ?? must be very fast
- ?? ????(medium-term scheduler)
- swapping
- degree of multiprogramming? ??
- memory -gt backing store
54.2 ???? ????(Process Scheduling)
- ?? ??(Context Switch)
- CPU? ? process?? ?? process? switch? ?
- save the state of the old process CPU? ???
??(PCB??) - load the saved state for new process CPU? ???
??(PCB??) - pure overhead performance bottleneck -gt
threads? ?? - context-switch time 1-1000microsecond
- address space ?? ?? memory ????? ??
4.3 ????? ?? ?????(Operations on Processes)
- ???? ??(Process Creation)
- ???? ?? ??? ?? fork, exec..
- ?? ????
- ?? ???? ?? ??? ?? ????? ??(memory, files) ??
- ? ???? ?? ? ???
- ?? ??
- ?? ??? ?? ? ?? ??? wait system call?
64.3 ????? ?? ?????(Operations on Processes)
cont.
- ? ????? 2?? (??? ?? ?? ???? ?)
- 1) ??? ??? ?? ?? fork
- 2) ??? ??? ? ????? ?? forkexec?
- execl ??? ?? ????
- execv ????? ???
- char av3
- av0 ls
- av1 -l
- av2 (char )0
- execv(/bin/ls, av)
- Unix? ? ??? ??
- 1) fork ?? process ??, ?? process? PID(Process
identifier)? ?? - 2) fork exec ???? ????? ????? ? ???? load
74.3 ????? ?? ?????(Operations on Processes)
cont.
- ???? ??(Process Termination)
- exit ??? ??
- ?? ??? ???? Return
- ???(???/???), ??? ??, I/O??? OS?? ???
- abort ??? ??
- ??? ??(??? ??? ?? ??? ? ??)
- ?? ?? ??
- ??? ??? ??? ?? ??? ?
- ??? task? ? ?? ?? ?? ?
- ??? ??? ?
- DEC VMS ?? Unix ???(cascading) ??
- ?? ?? -gt OS? ?? ?? ??
- (?) Unix
- exit system call? ???? ??
- wait system call return? ???? ??? pid
- wait(status)
- status ??? exit?? ??? ?? ????
- (?? 8bits 0(???? ??), ?? 8bits exit
status)
84.4 ???? ??(Cooperation Processes)
- ???? ???? ??
- ?? ?? (information sharing)
- ?? ?? ?? (computation speedup) parallel
computing?? - ???(modularity)
- ???(convenience) parallel computing??
- ???? ?? ? ???-???(producer-consumer)??
- compiler assembly code ??
- assembler assembly code ??, object code ??
- loader object code ??
- ???? ???? ??? ?????
- gt buffer? ??(?? ??? ??)
- gt ???? ???? ??? ??(???? ?? ?? ???? ??)
- ???-??? ?? ??
- 1. ?? ??(unbounded-buffer) ???-??? ??
- ???? ?? ??, ???? ??? ??? ??? ??
- 2. ?? ??(bounded-buffer) ???-??? ??
- ??? ? ? ??? ???? ??, ??? ?? ??? ???? ??
94.4 ???? ??(Cooperation Processes)
cont.
- ?? ?? ???-??? ?? -gt ???(LWP)? ?? ???
- ??-???? ??? ???
- var n
- type item ..
- var buffer array 0..n-1 of item
- in, out 0..n-1 inlt- next free position
outlt- first full position - empty in out
- full in 1 mod n out
- ??? ????
- repeat
- ...
- produce an item in nextp
- ...
- while in1 mod n out do no-op
- bufferin nextp
- in in 1 mod n
- until false
104.4 ???? ??(Cooperation Processes)
cont.
- ??? ????
- repeat
- while in out do no-op
- nextc bufferout
- out out 1 mod n
- ...
- Consume the item in nextc
- ...
- until false
- ??? ?? n-1 ? ??? ?? ? ?? -gt n ? ?? ? ??? ??(6?)
- in next free position
- out first full position
- empty, full ?? ?? ??? ?? ??
- ?? ??? ?? ?? in out
114.5 ???(Threads)
cont.
- ???? ?? PC
- ??? ? PC (a thread of control)? ?? address
space? ???? fork? ?? - ?? ????(LWP lightweight process) ???
- CPU? ???? ?? ??
- PC, ???? ??, ?? ??? ??
- ????? ?? task(code section, data section, OS
resources-open files, signals)? ?? (p113 ?? 4.8) - ?? ????(heavyweight process) 1 thread? ?? task
- ??
- ?? ???? CPU switching, thread context switch
- ???? ?? ???
- ?? ???? process switching, context switching
- ??? ?? ???(virtual memory page table ?? ?)
124.5 ???(Threads)
cont.
- ??
- ?? ??? ??(multiple-thread control)
- ? ?? PC, stack, ????(no protection)
- ?? ???? ??(multiple-process control)
- ??? PC, stack, address space, ???(protection)
- ???? ??
- CPU??
- ??, ??, ????
- ?? thread??
- block
- (?1) ?? ??
- ?? ???? ?? ?? process? disk access ?? block??
?? file server process ?? ?? - ?? ??? ??? ?? ?? task? ?? server thread ?? ??
- (?2) ??? ??? ??
- 2 threads ? ???? ??(better if on 2 processors)
134.5 ???(Threads)
cont.
- ???? ?? ??
- 1. kernel supported(????) Mash, OS/2 system
calls - ??? ????(fair scheduling)
- ??? ??? ?(switching is time consuming)
interrupt ?? ?? - 2. library supported(????? ??) Andrew(CMU)
library calls - ???? ????(unfair scheduling)
- ???? ??(switching is fast)
- ??? ?? ???? system call? ??? ?? system call ????
?? ?? ????? ???? ? - 3. hybrid approach(?? ??) Solaris 2
- kernel ??(system call ?? ??)
- single tasking Unix kernel ?? ?? ?? ??? ???
- multi tasking Mach kernel ????? ????(threads
are synchronous) - ?? ???? ??? ??? ???? ?? ??(?? ??? ?? ??? ??? ????
??) - (cf) asynchronous system? ?? locking mechanism??
144.5 ???(Threads)
cont.
- (?2)????(Solaris) 2.x
- SunOS Release 4.x - Solaris 1.x
- SunOS Release 5.x - Solaris 2.x
- Solaris 2? ??
- kernel??? user???? ??? ??
- symmetric multiprocessing(??? ?? ????)
- ? process? OS?? Master-slave? ??
- real-time scheduling(??? ????)
- ???? LWP(Light Weight Processes) a virtual
CPU - user-level
- stack? PC
- switching(linking with thread)? ???. ?? ?? ??.
- intermediate-level LWP
- PCB, register, ????, ??? ??
- ??? ???.
- kernel-level(???? ??)
- ??? ?????stack
- switching? ??? ???.
154.5 ???(Threads)
cont.
- p116 ?? Figure 4.9 Solaris 2? ???
- Many LWP, many CPU
- N user-level thread lt-gt l LWP
- 1 LWP lt-gt 1 Kernel-level thread 1 system call
- N Kernel-level thread lt-gt 1 CPU
- (?) 5? ?? ?? -gt 5 LWP??
- ? ?? ??? Kernel ??? I/O??? ???? ?
- Solaris 2??
- ? task? ? I/O??? ???? ?? block? ??? ??.
- ?? ??? ? LWP(kernel thread)? I/O ??? ???? ????
CPU? ? ??? ?? LWP(kernel thread)? ???? ?? ???
????. - ??
- Solaris 2.x System Administrators Guide,
- Threads Primer A Guide to Multithreaded
Programming, Bil Lewis, Daniel J.Berg, Prentice
Hall, 1996.
164.6 ????? ??(Interprocess Communication)
- ?? ?? lt- ? ????? ? ? ???? ?
- ?? ??? ??(shared-memory)
- ?? ???? ???? ?? ???? ???? ??
- (?)???? ???-??? ?? version 1
- ??? ?? ??(message-passing)
- IPC(interprocess-communication)?? ?? OS? ????
?? - (?)?? ?? ???-??? ?? version 2
- IPC?? ??(Basic Structure)
- IPC??? 2??
- send (message)
- receive(message)
- ???? P? Q? ??? -gt ???? ??
- ??
- ?? ???
- bus
- network
- send/receive??
174.6 ????? ??(Interprocess Communication)
cont.
- ??? ???? ???? ???
- ??(direct) ?? ?? ??
- ??(symmetric) ?? ???(symmetric) ??
- ??(automatic) ?? ???(explicit) ???
- ??(copy)? ?? ?? ?? ??(reference)? ?? ??
- ????(fixed-sized) ?? ????(variable-sized) ???
- ?? ??(Naming)
- 1) ????(Direct Communication)
- ??? ?? ? ????(sender/receiver)? ??? ??? ??
- Send(P, message) ???? P?? ??? ??
- Receive(Q, message) ???? Q??? ??? ??
- ???? ?? sender? receiver ??
- Send(P, message) ???? P?? ??? ??
- Receive(id, message) ??? ??????? ??? ??
- id ???? ?? ????? ???? ???
- ????? ??
- ???? ?? ??? ?? ???(limited modularity)
184.6 ????? ??(Interprocess Communication)
cont.
- (?? ??? ?) ???/??? ??
- ???(producer)
- repeat
- ...
- produce an item in nextp
- ...
- send(consumer, nextp)
- until false
- ???(consumer)
- repeat
- ...
- receive(producer, nextc)
- ...
- consume the item in nextc
- ...
- until false
194.6 ????? ??(Interprocess Communication)
cont.
- 2) ????(Indirect Communication)
- mailbox(ports) ?? ??
- send(A, message) mailbox A? ??? ??
- receive(A, message) mailbox??? ??? ??
- mailbox? ??
- ????? mailbox??
- OS? mailbox??
- ???(Buffering)
- ??? ??? ?? ??
- Zero capacity rendez-vous(no buffering)??? ??
- Bounded capacity ?? ?? ? ???? ???
- Unbounded capacity ?? ?? ? ???? ???
204.6 ????? ??(Interprocess Communication)
cont.
- ???? ??(asynchronous communication) ?? ??? ??
- ?? ?? ??? ?? ?? ??
- ? ??? ? ?? ??? ??
- P send(Q, message)
- receive(Q, message)
- Q receive(P, message)
- send(P, acknowledgment)
- ??? ??
- ??? ?? ????? ??? ???? ??
- ?? ??? ?? ?? ?? ? ??? ??? ?? ??? ??? ? ??
- ??? ?? ?? ?? ??? ??? ??? ??
- ??? ?? ????? ???? ?? ?? ??? ???
- Thoth
- reply(P, message) ? ??? ?? ????? ?? ????? ?? ??
- ??? ??(synchronous communication)
- RPC(Remote Procedure Call)? ?? ??
- sender subroutine call -gt reply? ??? ?? ?
- receiver ?? ??? reply
214.6 ????? ??(Interprocess Communication)
cont.
- ?? ??(Exception Conditions)
- centralized ?? distributed system?? ?? ??? ???
??(?? ??) ?? - ???? ??(Process Terminates)
- P? ??? Q? ??? -gt P? ?? ?
- P ??
- Q ?? ??? P? ??
- P? ??? Q? ??? ?? -gt Q? reply ???? ? ?? ?? ?
- ??? ??(Lost Messages)
- OS? ?? ? ?? ??
- sender? ?? ? ?? ??
- OS? ??, sender? ?? (-gt 12?)
- ??? ???(Scrambled Messages)
- ?? ??? ??(noise) ?? -gt ?? OS? ???
- ??????(check sums, parity, CRC)?? ??
224.6 ????? ??(Interprocess Communication)
cont.
- ?? Mach
- ?????? ?? OS
- ??? ??, task ? ????? ????
- port( mailbox)
- task ?? gt (kernel mailbox, notify mailbox) ??
- system calls
- msg_send
- msg_receive
- msg_rpc (remote procedure call)
- port_allocate ? mailbox ??, buffer size 8,
FIFO order - port_status ??? mailbox? ??? ? ??
- ??? ??
- ???? header
- ??? ??
- ? mailbox ??(? ? ??? sender? mailbox reply ??
return address ??) - ? ??? data portion ????(typed) ??? ???? ???
234.6 ????? ??(Interprocess Communication)
cont.
- send ??
- ?? mailbox? full? ??? ??? ??
- ?? mailbox? full??
- mailbox? ? ??? ?? ??? ??
- ?? n ??? ??
- ???? ?? ?? ??
- ???? ??? cache ??? ??? OS? ?? ??(???? ??? ??
mailbox? ???? ? reply only one pending
message) - line printer driver ? ?? ??? ??
- receive ??
- ?? mailbox ?? mailbox set??? ???? ???? ???? ?
- ??? mailbox??? ?? mailbox set ? ? mailbox??? ???
?? - ?? ??? ??? ?? n ??? ????? ???? ??
- ??? ???? ??
- double copy(sender -gt mailbox, mailbox-gt
receiver) - Mach? virtural memory ???? ?? ?? ??(?? ???? ??
???? ?? ?? ???? mapping ??)
244.6 ????? ??(Interprocess Communication)
cont.
- ?? Windows NT
- ??? ?? ???? ?? ?? ????? ?? ??(local Procedure
Call) - ?? ??(connection port)? ?? ??(communication port)
?? - ?? ??
- ?????? ?? ?? ??? ?? handle? open
- ?????? ?? ??
- ??? ? ?? ???(private) ?? ??? ???? ??????? ? ?? ?
??? handle? ???. - ?????? ??? ?? ?? ??? handle? ???? ???? ????
????(callback)? ?? ??(reply)? ??? - ? ?? ??? ?? ??
- ??? ??? ?? ?? ???? ??, callback ?? ??
- ?? ???? ?? ??(section object)? ??, callback ?? ??
- quick LPC ?????? ?? ?? ? quick LPC ??, ???
????? ?? ?? ???(dedicated server thread) ?? - ?? ??, ??? ?? 64KB ?? ??, ???? ???? ? ?? ??
??(event pare object) ?? - ?? ??? ??, ?? ?? ??, ??? ????? ???? overhead ??
- ?? ?? ? ???? ?? ?? ??
- ??? ?? overhead ???? ?? ????? ? ???? batch ??? ?