Modern Operating Systems 笔记 - Processes
pseudoparallelism
The illusion of parallelism while CPU is switching from process to process quickly.
The Process Model
process is an instance of an executing program, is the activity of a program.
If a program is running twice, it counts as two processes.
Process Creation
Processes are created when
- System init
- Process creation system call by a running process
- A user request to create a new process.
- Init of a batch job.
In Unix, fork
system call creates an exact clone of the calling process. execve
is another syscall used to change its memory image and run a new program.
This separation allows the child to manipulate its file descriptors after
fork
but before theexecve
in order to accomplish redirections.
In Windows, CreateProcess
system call handles both process creation and loading with 10 parameters.
It's possible for a newly created process to share resources such as open files.
Process Termination
When processes terminate
- Normal exit (voluntary)
- Error exit (voluntary)
- Fatal error (involuntary)
- Killed by another process (involuntary)
Voluntary termination: exit
in UNIX and ExitProcess
in Windows. Kill someother process: kill
in UNIX and TerminateProcess
in Windows.
Process Hierarchies
In UNIX, a process and all its children and further descendants form a process group. User signals are sends to all members in the group.
init
is the first process created in boottime. Thus all processes in the whole system belong to a single tree withinit
as the root.
Windows has no concept of process hierarchy, despite that a handle(a special token used to control the child) is returnd when creating a new process.
Process States
- Running (actually using the CPU)
- Ready (runnable; temporariy stopped to let another process run)
- Blocked (unable to run util some external event happens)
Implementation of Processes
The OS maintains a process table , with one entry ( process control block ) per process. Each entry contains program counter, stack pointer, memory allocation, status of open files, scheduling information registers, and everything need to save when swapped out.
With a PCB, process can be saved when interrupted and swapped out. The interrupt routine may be as follows:
- Hardware stacks program counter, etc
- Hardware loads new program counter from interrupt vector
- Assembly language procedure saves registers.
- Assembly language procudure sets up new stack.
- C interrupt service runs (typically reads and buffers input).
- Scheduler decides which process is to run next.
- C procedure returns to the assembly code.
- Assembly language procedure starts up new current processes.
Modeling Multiprogramming
Suppose p is the fraction of I/O time for a process. n is current count of processes. Then
$CPU~utilization = 1 - p^n$
where n is called the degree of multiprogramming .
本文采用 知识共享署名 4.0 国际许可协议(CC-BY 4.0)进行许可,转载注明来源即可: https://harttle.land/2013/11/17/modern-os-processes.html。如有疏漏、谬误、侵权请通过评论或 邮件 指出。