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 .
转载请注明来源： http://harttle.com/2013/11/17/morden-os-processes.html 欢迎对文章中的引用来源进行考证，欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论（可能需要在能访问 disqus 服务的网络），也可以邮件至 email@example.com。