Operating system knowledge

Source: Internet
Author: User

Reprinted: http://www.cnblogs.com/mydomain/category/262673.html

For Job Search ~

1. Communication Methods between several processes

# Pipe: a pipe is a half-duplex communication method. data can only flow in one direction and can only be used between unrelated processes. The kinship of a process usually refers to the parent-child process relationship.
# Named pipe: A famous pipe is also a half-duplex communication method, but it allows communication between unrelated processes.
# Semophore: a semaphore is a counter that can be used to control access to shared resources by multiple processes. It is often used as a lock mechanism to prevent other processes from accessing a shared resource. Therefore, it is mainly used for synchronization between processes and between different threads in the same process.
# Message Queue: a message queue is a linked list of messages stored in the kernel and identified by the Message Queue identifier. The message queue has overcome the disadvantages of few signal transmission information, the pipeline can only carry unformatted byte streams, and the limited buffer size.
# Signal (Sinal): a signal is a complex communication method used to notify the receiving process that an event has occurred.
#
Shared Memory)
: Shared memory is the memory mapped to a segment that can be accessed by other processes. The shared memory is created by one process, but can be accessed by multiple processes. Shared memory is the fastest IPC
It is specially designed for other inter-process communication modes with low operation efficiency. It is often used with other communication mechanisms, such as signal two, to achieve synchronization and communication between processes.
# Socket: the socket is also a mechanism for inter-process communication. Different from other communication mechanisms, it can be used for different and inter-process communication.

2. Process Synchronization and mutex

There are many figures. For more information, see operating system principles.

3. kernel and user

When a task (process) executes the system call and executes the kernel code, it indicates that the process is in the kernel state, and the processor is executed in the kernel code with the highest privilege level (level 0, when the process is in the kernel state, the kernel stack of the current process is used for the executed kernel code. Each process has its own kernel stack. When a process executes user code, it says it is in the user State. At this time, the processor runs in the (3) User code with the lowest privilege level.

When a user program is being executed and suddenly interrupted, the user program can also be symbolic to be in the kernel state of the process, because the interrupt handler will use the kernel stack of the current process. This is similar to the status of processes in the kernel state. Kernel state and user State are two operating systems, there is no inevitable relationship with Intel CPU, Intel CPU provides three levels of Ring0-Ring3 running mode, ring0 level highest, ring3 lowest.

Linux uses the ring3 running user State, ring0 as the kernel state, and ring1 and ring2 are not used. Ring3 status cannot access the address space of ring0, including code and data. The 4 GB address space for Linux processes. The 3g-4g address space is shared by all users. It is the kernel-state address space, which is stored in the entire kernel code and all kernel modules, and the data maintained by the kernel. When a user runs a program, the process created by the program starts to run in the user State. If you want to perform file operations, network data transmission, and other operations, you must use a system call such as write and send, these system calls will call the code in the kernel to complete the operation. At this time, you must switch to ring0 and then enter the kernel address space in 3gb-4gb to execute the code to complete the operation. After the operation is completed, switch back to ring3, return to the user State. In this way, user-state programs cannot operate on the kernel address space at will, thus providing security protection.

Protection Mode: through memory page table operations and other mechanisms, ensure that the address space between processes does not conflict with each other, and the operation of one process does not modify the data in the address space of another process. In kernel mode, the CPU can execute any command. In user mode, the CPU can only execute non-privileged commands. When the CPU is in the kernel state, you can enter the user State at will. When the CPU is in the user State, you can only enter the kernel state through interruption. Generally, the program runs in the user State at the beginning. When the program needs to use system resources, it must enter the kernel state by calling the Soft Interrupt.

Use nm to view the symbol table content of the user State Program

Use System. Map (kernel symbol table) to view kernel symbol table content

1) print the user's state function address in the test program and call the system call (print the system call function address in the kernel ), use the "user-state symbol table" and "kernel-state symbol table" examples to illustrate the differences between kernel-state and user-state address space

2) kernel state address ing ioremap (); User State address ing MMAP ()

4. System Call

The kernel communication method used by all processes in the system is system call. For example, when a process requests the kernel service, it uses a system call. Generally, a process cannot access the system kernel. It cannot access the memory segments used by the kernel or call kernel functions. The hardware structure of the CPU ensures this. Only system calls are an exception. The process uses the appropriate values in the Register to jump to the pre-defined code in the kernel for execution (of course, the code is read-only ). In an Intel-structured computer, this is implemented by the 0x80 interrupt.

The position in the kernel that a process can jump to is system_call. The process at this location checks the system call number, which will tell the kernel process what the requested service is. Then, it finds the system call table sys_call_table, finds the address of the kernel function to be called, calls the function, and returns the result.

Therefore, if you want to change a function called by the system, you need to write a function of your own, and then change the pointer in sys_call_table to point to this function, finally, use cleanup_module to restore the system call table to its original state.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.