Notes on Processes, Context, Context Switching

Download Report

Transcript Notes on Processes, Context, Context Switching

Notes on Processes, Context,
Context Switching
The following slides contain partially
quoted statements from various
Wikipedia pages.
fork()
• In computing, when a process forks, it creates a copy of itself, which
is called a "child process." The original process is then called the
"parent process". More generally, a fork in a multithreading
environment means that a thread of execution is duplicated,
creating a child thread from the parent thread.
• Under Unix and Unix-like operating systems, the parent and the
child processes can tell each other apart by examining the return
value of the fork() system call. In the child process, the return value
of fork() is 0, whereas the return value in the parent process is the
PID of the newly-created child process.
• The fork operation creates a separate address space for the child.
The child process has an exact copy of all the memory segments of
the parent process, though if copy-on-write semantics are
implemented actual physical memory may not be assigned (i.e.,
both processes may share the same physical memory segments for
a while). Both the parent and child processes possess the same
code segments, but execute independently of each other.
CreateProcess Function
• Creates a new process and its primary thread.
The new process runs in the security context
of the calling process.
Syntax
BOOL WINAPI CreateProcess(
__in_opt LPCTSTR lpApplicationName,
__inout_opt LPTSTR lpCommandLine,
__in_opt LPSECURITY_ATTRIBUTES
lpProcessAttributes,
__in_opt LPSECURITY_ATTRIBUTES
lpThreadAttributes,
__in BOOL bInheritHandles,
__in DWORD dwCreationFlags,
__in_opt LPVOID lpEnvironment,
__in_opt LPCTSTR lpCurrentDirectory,
__in LPSTARTUPINFO lpStartupInfo,
__out LPPROCESS_INFORMATION
lpProcessInformation );
Context
• In computer science, a task context (process, thread ...) is the
minimal set of data used by this task that must be saved to allow a
task interruption at a given date, and a continuation of this task at
the point it has been interrupted and at an arbitrary future date.
• The concept of context assumes significance in the case of
interruptible tasks, wherein upon being interrupted the processor
saves the context and proceeds to serve the Interrupt service
routine. Thus the smaller the context the smaller is the latency.
• These data are located in:
– Processor registers
– Memory used by the task
– On some Operating systems, control registers used by the system to
manage the task
• The storage memory (files) is not concerned by the "task context" in
the case of a context switch; even if this can be stored for some
uses (Checkpointing).
Context Switch
• A context switch is the computing process of storing
and restoring the state (context) of a CPU such that
multiple processes can share a single CPU resource.
• The context switch is an essential feature of a
multitasking operating system.
• Context switches are usually computationally intensive
and much of the design of operating systems is to
optimize the use of context switches.
• A context switch can mean a register context switch, a
task context switch, a thread context switch, or a
process context switch. What constitutes the context is
determined by the processor and the operating system.
State
• In computer science and automata theory, a
state is a unique configuration of information
in a program or machine.
• One of the key concepts in computer
programming is the idea of state, essentially a
snapshot of the measure of various conditions
in the system.
Interrupts
• In computing, an interrupt is an asynchronous signal from
hardware indicating the need for attention or a
synchronous event in software indicating the need for a
change in execution.
• A hardware interrupt causes the processor to save its state
of execution via a context switch, and begin execution of an
interrupt handler.
• Software interrupts are usually implemented as instructions
in the instruction set, which cause a context switch to an
interrupt handler similar to a hardware interrupt.
• Interrupts are a commonly used technique for computer
multitasking, especially in real-time computing. Such a
system is said to be interrupt-driven. [1]
• An act of interrupting is referred to as an interrupt request
("IRQ").