1In the system, each possible type of exception is assigned a unique non-negative integer exception number (Exception number). Some of these numbers are assigned by the processor designer and others are assigned by the operating system kernel designer. For example, Division0Item, page missing, memory access violation, breakpoint, and Arithmetic overflow. Examples of the latter include system calls and externalI/ODevice signal.
When the system is started,OSInitialize a jump table called an exception tableKInclusion exceptionKProcessingProgram.
2If the control is transferred from a user program to the kernel, all these projects (Item) Is pushed to the kernel stack, rather than to the user stack.
Exception handlers run in kernel mode, which means they have full access to all resources.
3ModernOSMake these sudden changes (Abrupt Changes) Is called an exception, such as an interruption.
4, Exception category
Exceptions can be divided into four classes: interrupts, traps, faults, and aborts.
Note:Anync (Asynchronous),Sync (Synchronization)
Asynchronous exceptions are external to the processor.IoEvents in the device are generated. A synchronization exception is a direct result of executing a command.
1) Trap (Trap)
A trap is an intentional exception and is the result of executing a command. The most important purpose is to provide a process-like interface between a user program and the kernel, called a system call.
User programs often need to request services from the kernel, such as readingRead, Create a new processFork, Load a new programExecveTo terminate the current process.Exit.
From the programmer's perspective, system calls are the same as normal function calls. Actually, they are implemented differently. Common function calls run inUser ModeThe user mode limits the types of commands that can be executed by the function, and they can only access the same stack as the called function. system calls occur inKernel ModeThe kernel mode allows the system to call and execute commands and access the stack defined in the kernel.
2) Fault (Fault)
A typical failure example is a page missing exception.
5, Context (ContextIs composed of the States required for the program to run correctly. This status includesCodeAnd data, its stack, its general purpose register content, its program counters, environment variables, and a set of open file descriptors.
PCA sequence of values is called a logical control flow. A multi-task is also called a time slice (Time Slicing).
6View system calls
LinuxProvided160System calls,Man syscilsQuery.
MAN 2 infoGet_ SyscallMacro; you can directly call any "system call ".
7, Operating process Tool
Strace: Prints a trace of each system call invoked by a program and its children.
Compile your program with-static to get a cleaner trace without a lot of output
Related to shared libraries.
PS: Lists processes (including zombies) currently in the system.
Top: Prints information about the resource usage of current processes.
Kill: Sends a signal to a process.
/Proc: A virtual filesystem that exports the contents of numerous kernel data
Structures in an ASCII text form that can be read by user programs. For example, Type
"Cat/proc/loadavg" to see the current load average on your Linux system.
<Computer systems: a programmer's perspective>