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.
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.
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
forkbut before the
execvein order to accomplish redirections.
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.
When processes terminate
- Normal exit (voluntary)
- Error exit (voluntary)
- Fatal error (involuntary)
- Killed by another process (involuntary)
exit in UNIX and
ExitProcess in Windows. Kill someother process:
kill in UNIX and
TerminateProcess in Windows.
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.
initis the first process created in boottime. Thus all processes in the whole system belong to a single tree with
initas 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.
- 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.
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。学识粗浅写作仓促，如有错误辛苦评论或 邮件 指出。