Linux Interim Summary
- The first week of the Linux curriculum Experiment and Summary: [http://www.cnblogs.com/20135302wei/p/5218607.html]
The core idea of the von Neumann architecture is to store program computers. There are two kinds of instructions in the computer, one is the user instruction, the other is the system call.
When the user uses the computer, the computer according to its assembly of instructions step to run, when the use of system calls, and then return to the user mode, to ensure the stability of the system.
- Stack change of call execution in the program
- Assembly Base General Purpose register
16-bit 32-bit
AX EAX Accumulator
BX EBX Base Register
CX ecx Count Register
DX edx Data Register
BP EBP Stack Base address pointer
SI ESI Variable address register
DI EDI Variable address register
SP ESP Stack top pointer
- Linux Course second week experiment and summary: [http://www.cnblogs.com/20135302wei/p/5248478.html]
- function calling convention
function calling convention |
parameter Pass Order |
responsible for cleaning up parameters consumed by Stack |
__pascal |
left-to-right |
caller |
__stdcall |
Right-to-left |
tuned function |
__cdecl |
right-to-left |
Caller |
-
The code that invokes the function and the called function must take the same function as the calling convention for the program to run correctly.
windows the default function calling convention for a C + + program is __cdecllinux the default rule for GCC is __stdcall
-
Three magic weapon
store program computer, function call stack, interrupt mechanism
-
Two sword
interrupt context, process context toggle
- Third week of Linux Course Experiment and Summary: [http://www.cnblogs.com/20135302wei/p/5273142.html]
- Overview of the startup process for computers
- x86 the first action cs:eip=ffff:0000h of the CPU boot (converted to a physical address of 000ffff0h because the 16-bit CPU has 20 address lines), which is the location of the BIOS program.
- After the BIOS routine detects the hardware and completes the corresponding initialization, it looks for the bootable media, and after locating the bootloader into the specified memory area, the control is given to the boot program. This is usually the first sector of the hard disk MBR and the active partition of the boot program loaded into memory (that is, load bootloader), the full load after the control to bootloader.
- The bootloader bootloader begins to be responsible for operating system initialization and then starts the operating system. The kernel, INITRD, and root partitions and directories are typically specified when the operating system is started, such as Root (hd0,0), kernel (hd0,0)/bzimage Root=/dev/ram init=/bin/ash,initrd ( hd0,0)/myinitrd4m.img
- The kernel boot process includes start_kernel before and after, all of which are pre-initialized assembly instructions, followed by the OS initialization of the C code, and finally the first user-state process init.
- Generally in two-phase boot, first take advantage of the INITRD memory file system, and then switch to the hard disk file system to continue to boot.
- There are two main features of the INITRD file:
- 1, provide the boot required but the kernel file (ie Vmlinuz) does not provide the driver module (modules)
- 2, responsible for loading the root file system on the hard disk and executing the/SBIN/INIT program, which will continue the boot process
- Fourth week of Linux Course Experiment and Summary: [http://www.cnblogs.com/20135302wei/p/5289989.html]
- System_call is the entry point for all system calls in Linux, with at least one parameter per system call, which is the system call number passed by eax
- An application calls the fork () encapsulation routine, the value of the EAX register is set to 2 (that is, __nr_fork) before the int $0x80 is executed.
- The number of parameters cannot be more than 6 (EBX,ECX, edx, ESI, EDI, EBP) beyond the system call number (EAX)
- When the user-state process invokes a system call, the CPU switches to the kernel state and starts executing a kernel function.
- In Linux, which executes a system call by executing an int $0x80, this assembly instruction produces a programming exception with a vector of 128
- Fifth week of Linux Course Experiment and Summary: [http://www.cnblogs.com/20135302wei/p/5316624.html]
-
- Add time and Time-asm commands to Menuos (four-step Operation command)
- Sixth week of Linux Course Experiment and Summary: [http://www.cnblogs.com/20135302wei/p/5329518.html]
- The role of processes: linking signals, interprocess communication, memory management, and file systems
- The three main functions of the operating system: process management, memory management, file system
- The kernel distinguishes each process by its unique process identity PID
- Fork, Vfork, and clone three system calls can create a new process, and all are created by calling Do_fork to implement the process
Process number 1th is the ancestor of all user-state processes, and process number No. 0 is the ancestor of all kernel threads
- Seventh week of the Linux Course Experiment and Summary: [http://www.cnblogs.com/20135302wei/p/5352571.html]
- execve system call
-
Shell calls Execve to pass command-line arguments and environment parameters to the main function of the executable program
int Execve (const char * filename,char * CONST argv[],CHAR * Const envp[ ]);
The
- execve () is used to execute the file path represented by the argument filename string, the second parameter is passed to the execution file using an array of pointers, and it needs to end with a null pointer (null), and the last parameter is an array of new environment variables passed to the execution file.
-
Library functions exec* are EXECVE package routines
Execve and Fork are a special point of system invocation: The general is to fall into the kernel state and return to the user state. Fork parent process and general process scheduling, the child process returns to a specific point ret_from_fork, the child process starts from ret_from_fork and then returns to the user state ; Execve Special: Execute to executable program--fall into kernel--construct new executable file--Overwrite the original executables--return to the new executor, as a starting point (that is, main function), need to construct his execution environment;
Linux Eighth Week experiment and summary: [http://www.cnblogs.com/20135302wei/p/5388498.html]
- process switching is implemented in the kernel at the time of the following three times : strong>
-
-
Interrupt processing (including clock interrupt, I /O interrupts, system calls, and exceptions), call schedule () directly or return to the user state based on the need_resched tag call schedule ();
-
Kernel threads can call schedule () directly for process switching, Can also be scheduled during interrupt processing, that is, the kernel thread as a class of special processes can be active scheduling, but also can be passively dispatched;
-
User-state processes cannot implement proactive scheduling, but can only be dispatched by a point in time after the kernel state. scheduling during interrupt processing.
Linux Course Textbook 1–2 Study notes: [Http://www.cnblogs.com/20135302wei/p/5280800.html]
- The activity of the processor must be one of the following three:
- Run in user space, execute user process
- Runs in kernel space, is in the process context, executes on behalf of a particular process
- Runs in kernel space, is in the interrupt context, is independent of any process, and handles a specific interrupt
- Features of kernel development
- Kernel development can neither access C library nor access standard C header files
Response: The Include/linux folder contains the required kernel header files.
- The kernel programming must use the GNU C
- Kernel programming lacks a memory protection mechanism like user space
The memory in the kernel is not paged.
- Difficult to perform floating-point arithmetic during kernel programming
- The kernel gives each process only a small fixed-length stack
- Because the kernel supports asynchronous interrupts, preemption, and SMP, you must always be aware of synchronization and concurrency
SMP: Symmetric multi-processing system.
Common ways to solve competition: spin locks and semaphores .
- To consider the importance of portability
such as keeping the byte order, 64 bits to it, not assuming word length and page lengths.
Linux Course Textbook 3rd study notes: [Http://www.cnblogs.com/20135302wei/p/5335493.html]
-
Processes and Threads
Task structure of the process
Process and thread creation
Termination of the process
- Linux Course Textbook 4th study notes: [Http://www.cnblogs.com/20135302wei/p/5389439.html]
Scheduling: Scheduling is a balanced process. On the one hand, it is to ensure that each operation of the process to maximize the use of CP, on the other hand, to ensure that the process of fair use of the CPU.
Scheduling function: Determines which process runs and how long the process runs.
Scheduling implementation principle: Related to the priority of the process
Method of scheduling implementation on Linux: O (1) Scheduling algorithm
Scheduling-related system calls
- Linux Course Textbook 5th study notes: [Http://www.cnblogs.com/20135302wei/p/5302683.html]
- How the Linux kernel implements system calls and performs a chain reaction of system calls: into the kernel, passing system call numbers and parameters, executing the correct system call function, and bringing the return value back to the user space.
- The SYSTEM_ call () function checks the validity of a given system invocation number by comparing it to Nr_ syscalls. If it is large or equal to Nr_syscalls, the function returns-enosys
- Linux Course Textbook 18th Study notes: [Http://www.cnblogs.com/20135302wei/p/5327484.html]
- The debugging process is actually a kind of behavior that seeks to achieve the deviation from the goal.
Oops is the most common way that the kernel informs users of unfortunate occurrences.
Kernel bugs may be caused by:
- 错误代码- 同步时发生的错误,例如共享变量锁定不当- 错误的管理硬件- ……
Symptoms of a kernel bug attack may include:
- 降低所有程序的运行性能- 毁坏数据- 使得系统处于死锁状态- ……
Kernel development takes into account unique issues over user development, such as:
- 定时限制- 竞争条件- ……原因是允许多个线程在内核中同时运行。
- "In-depth understanding of computer Systems" Chapter 7th study notes: [Http://www.cnblogs.com/20135302wei/p/5357264.html]
-
-
link--static link, dynamic Link ( link includes two main tasks: symbol parsing and relocation)
-
Link file creation and referencing--GCC, AR RCS, Sharedj, and fpic command parameters
-
relocation--reposition entry, reposition symbol reference (PC relative reference and absolute reference)
-
target file--relocatable the target file (which details the structure and format of the elf relocatable file), Executable target file, shared destination file
A link (linking) is the process of collecting and combining various pieces of code and data into a single file that can be loaded (or copied) into memory and executed.
A link can be executed at compile time, when the source code is translated into machine code, or it can be executed at load time , when the loader is loaded into storage and executed, or even at run time . Executed by the application.
20135302 Wei Quiet--linux Course Summary