Professional Documents
Culture Documents
An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks
Process a program in execution; process execution
4.1
Process State
As a process executes, it changes state new: The process is being created. running: Instructions are being executed. waiting: The process is waiting for some event to occur. ready: The process is waiting to be assigned to a process. terminated: The process has finished execution.
4.2
4.3
memory, ready and waiting to execute. Device queues set of processes waiting for an I/O device. PCB migration between the various queues.
4.4
4.5
4.6
Context Switch
When CPU switches to another process, the system must Save the state of the old process Load the saved state for the new process.
Context-switch time is overhead; the system does no
4.7
4.8
Dispatcher
Dispatcher module gives control of the CPU to the
4.9
Process Creation
Parent process create children processes, which, in turn
create other processes, forming a tree of processes. Resource sharing (one of)
Parent and children share all resources. Children share subset of parents resources. Parent and child share no resources.
Address space (one of) Child duplicate of parent. Child has a program loaded into it.
Execution (one of) Parent and child execute concurrently. Parent waits until child terminate.
4.10
Process Termination
Process executes last statement and tells the OS Output status from child to parent Process resources are deallocated by operating system.
Parent may terminate execution of children processes Child has exceeded allocated resources. Task assigned to child is no longer required. Parent is exiting (options) Operating system does not allow child to continue if its parent terminates. Cascading termination.
4.11
4.12
UNIX PCBs
Control blocks associated with a process are stored in the
kernel.
Information in these control blocks is used by the kernel for
process control and CPU scheduling. The virtual address space of a user process is divided
into text (program code), data, and stack segments. Every process with sharable text has a pointer from its process structure to a text structure.
Always resident in main memory. Records how many processes are using the text segment Records where the page table for the text segment can be
4.13
4.14
segments of the child process Copying the user structure preserves open file descriptors, user and group identifiers, signal handling, etc.
4.15
processess virtual memory space with a new program exit terminates a process A parent may wait for a child process to terminate; wait provides the process id of a terminated child so that the parent can tell which child terminated. wait allows the parent to collect performance statistics about the child A zombie process results when the parent of a defunct
4.16
4.17
Process Hierarchy
All user processes are descendants of one original
login name to login. login sets the numeric user identifier of the process to that of the user Executes a shell which forks subprocesses for user commands.
4.18
4.19
Process Privileges
setuid bit sets the effective user identifier of the process
to the user identifier of the owner of the file, and leaves the real user identifier as it was. setuid scheme allows certain processes to have more than ordinary privileges while still being executable by ordinary users.
4.20
Process Groups
Set of related processes that cooperate to accomplish a
common task. Only one process group may use a terminal device for I/O at any time.
The foreground job has the attention of the user on the
terminal. Background jobs nonattached jobs that perform their function without user interaction.
Access to the terminal is controlled by process group
signals.
4.21
Process Groups
Each job inherits a controlling terminal from its parent. If the process group of the controlling terminal matches the group of a process, that process is in the foreground. SIGTTIN or SIGTTOU freezes a background process that attempts to perform I/O; if the user foregrounds that process, SIGCONT indicates that the process can now perform I/O. SIGSTOP freezes a foreground process.
4.22
Signals
Facility for handling exceptional conditions similar to
software interrupts. The interrupt signal, SIGINT, is used to stop a command before that command completes (usually produced by ^C). Signal use has expanded beyond dealing with exceptional events.
Start and stop subprocesses on demand SIGWINCH informs a process that the window in which output
is being displayed has changed size. Deliver urgent data from network connections.
4.23
Threads
A thread (or lightweight process) is a basic unit of CPU
Collectively known as a task. A traditional or heavyweight process is equal to a task with one thread.
4.24
4.25
Benefits
Responsiveness Threads provide a mechanism that allows sequential processes to make blocking system calls while also achieving parallelism. In a multiple threaded task, while one thread is blocked and waiting, a second thread in the same task can run.
Resource Sharing Economy Utilization of MP Architectures
4.26
Thread Implementations
User-level threads library POSIX Pthreads Mach C-threads Solaris threads
Kernel Threads Windows 95/98/NT/2000 Solaris Linux
4.27
Many-to-One
Many user-level threads mapped to single kernel thread.
Used on systems that do not support kernel threads.
4.28
One-to-One
Each user-level thread maps to kernel thread.
Examples Windows 95/98/NT/2000 OS/2
4.29
Many-to-Many Model
Allows many user level threads to be mapped to many
kernel threads. Allows the operating system to create a sufficient number of kernel threads.
Solaris 2
4.30
Pthreads
A POSIX standard (IEEE 1003.1c) API for thread creation
and synchronization. API specifies behavior of the thread library, implementation is up to development of the library. Common in UNIX operating systems.
4.31