TDC 311 Process Description and Control Dr. C.M.White Two

advertisement
TDC 311
Process Description and Control
Dr. C.M.White
Two-state process model
Reasons for process creation
New batch job
Interactive log on
Created by OS to provide a service
Spawned by existing process (for purposes of modularity or to exploit parallelism)
Reasons for process termination
Normal completion
Time limit exceeded
Memory unavailable
Bounds violation
Protection error
Arithmetic error
Time overrun (process has waited too long for an event to happen)
I/O failure
Invalid instruction
Privileged instruction
Data misuse
Operator or OS intervention
Parent termination
Parent request
TDC 311 Process Description
1
What if the process has to wait for something to finish (like I/O)?
Five-state process model
Model with suspend states
Use Suspend state when all processes are blocked. When moved to Suspend, job is swapped out
to secondary storage, so a new process can be brought in.
Suspend, ready - has been suspended and event has occurred.
Suspend, blocked - blocked and suspended.
TDC 311 Process Description
2
Process description
1. Control structures
memory tables - keep track of what memory is assigned to what processes
I/O tables
file tables
process tables - keeps a list of pointers to process images
2. Process attributes (or what goes into a process control block(PCB))
identifier of this process
identifier of the process that created this process
user identifier
user-visible registers
control and status registers
stack pointers
process state indicator
scheduler priority indicator
scheduling-related information
event (that this process is currently waiting for)
data structuring (this process may be linked to other processes in a queue, ring, or some
other structure)
various flags, signals, and messages that may be associated with communication
between two independent processes
process privileges (does this process have access to certain system utilities and
services?)
memory management (pointers to segment and/or page tables)
resource ownership and utilization (what opened files does this process own?)
Process control
What kind of >things= can a process do?
process can be in either user mode or supervisor mode
process can create or spawn another process. If a process can spawn another process, OS
probably does the following:
assigns a unique PID to new process
entry added to process table
allocate space for process image
PCB is initialized
appropriate linkages are set
misc. Data structures created, such as accounting information
TDC 311 Process Description
3
process can terminate another process
process switching - when an interrupt occurs, an interrupt handler takes over; this may
switch processes. If processes aren=t switched, it is just a context switch (e.g. an I/O
interrupt occurs and all that happens is a flag or two are reset.) A context switch may
occur without changing the state of the process that is currently in the Running mode. If a
process switch is performed, the following will probably be done:
save the context of the process, including program counter and other registers
update the PCB of the process currently running to denote blocked,ready or
whatever
move the PCB of this process to the appropriate queue
select another process for execution
update the PCB of the process selected
update memory management structures
restore the context of the processor to that which existed at the time the selected
process was last switched out of the Running state by loading in the previous
values of the program counter and other registers.
Note: Some authors differentiate between context switch and process switch, while some do not.
Threads
Like lite beer, a thread is a lite process (or lightweight process)
Each thread may contain:
thread ID
program counter
stack
register set
child threads
state
It shares with other threads belonging to the same process its
code
data section
other operating system resources such as open files and signals
One process may have multiple threads.
Why a thread? A thread takes far less time to create, and much less space.
A group of peer threads share code, address space, and OS resources.
If they share things, is security a problem? No, because the threads do not belong to unrelated,
TDC 311 Process Description
4
competing processes, but to the same process.
Threads also make inter-communication easier since multiple threads share same files/storage.
Threads operate pretty much like processes - they have a state, they can get blocked, and they can
spawn new threads.
Common examples: A database server on a LAN - as each new query arrives, a new thread is
spawned to service the request (one process - multiple threads). When a thread gets blocked
requesting disk I/O, another thread can start up almost immediately and begin its operation.
A web browser might have one thread display images or text while another thread retrieves data
from the network.
A word processor may have a thread for displaying graphics, another thread for reading
keystrokes from the user, and a third thread for performing spelling and grammar checking in the
background.
There are kernel threads and there are user threads.
The Process in VAX/VMS
From VAX/VMS OS Concepts by Miller
“Only way a process can be created is by the action of another process.”
Always some processes running on a system (do SHOW SYSTEM), e.g. SWAPPER, ERRFMT,
JOB_CONTROL, ...
These processes can be:
SUS Suspended (can be outswapped)
COM Computable (waiting in ready queue) (can be outswapped)
HIB Hibernating (can be outswapped)
LEF Waiting for a local event flag
CUR Currently running
and others
Each process has a priority assigned to it: 0 - 31 (31 is the highest) (4 is typical interactive users).
TDC 311 Process Description
5
User Login
1. Terminal device reports via interrupt that a key has been pressed.
2. Terminal driver attempts to associate the keystroke to an existing process using the translation
table.
3. Since no association exists (new LOGIN), JOB_CONTROL is awakened.
4. JOB_CONTROL calls function $CREPRC which creates a process image which will
eventually become the user=s. For now, the new process is just like JOB_CONTROL and has
the following info:
PCB Vector
PCB
ACB (AST Control Block)
Process ID
Forward Link
Backward Link
Housekeeping
ACB Links
Physical PCB Ptr
Quota Limits
Local Event Flags
EF Cluster Ptrs
PID
PHD Ptr
JIB Ptr
Privileges
ACL Links
State
Priority
Name
Asynchronous System Traps
PHD (Process Header)
Accounting
Physical PCB
Memory Info (for the code)
JIB
Job Info Block
ACL
Access Rights
Event Flags etc
All quotas, privileges, priorities are temporarily the same as JOB_CONTROL.
Image of LOGINOUT is placed into its PHD Memory Info.
5. $CREPRC marks new process as computable outswapped (COMO) and informs VMS to
insert it into the appropriate queue.
6. $CREPRC returns to JOB_CONTROL.
TDC 311 Process Description
6
7. JOB_CONTROL hibernates.
8. Eventually, the new process gets a chance to execute, which runs LOGINOUT procedure.
9. LOGINOUT prompts for Username and Password using the $QIOW routine.
10. LOGINOUT takes Username and Password and searches file SYSUAF.DAT for valid
account.
11. If account is valid, LOGINOUT extracts following info from user account info:
process name (usually user name)
default disk drive and directory info
user privileges
user quotas
run-time restrictions
process priority
default CLI (command line interpreter, or shell)
and updates the PCB accordingly.
12. LOGINOUT initializes the CLI, which is usually DCL program (the standard VAX shell).
13. DCL eliminates LOGINOUT.
14. DCL executes LOGIN.COM file.
15. DCL puts $ on screen via $QIOW.
TDC 311 Process Description
7
Download