Experimental analysis: https://www.zhihu.com/column/c_142990858
Linux is an open source operating system. Users can tailor and modify the kernel according to their own system needs to customize systems with more appropriate functions and higher operating efficiency. Therefore, compiling the Linux kernel is a necessary basic skill for kernel development.
Adding new system calls as needed in the system is a common method to modify the kernel. Through this experiment, readers should understand the process of linux system processing system calls and the method of adding system calls.
(1) Add a system call to implement the modification or reading function of the nice value of the specified process, and return the latest nice value and priority prio of the process. It is recommended to call the prototype as:
int mysetnice(pid_t pid, int flag, int nicevalue, void __user * prio, void __user * nice);
Parameter meaning: pid: process ID.
flag: If the value is 0, it means reading the nice value; if the value is 1, it means modifying the nice value.
Prio, nice: the current priority and nice value of the process. Return value: Return 0 when the system call is successful, and return the error code EFAULT when the system call fails.
(2) Write a simple application test added in (1).
(3) If the kernel function of Linux is called in the program, it is required to read the source code of the relevant function in depth.
The module mechanism provided by Linux can dynamically expand Linux functions without recompiling the kernel, and has been widely used in the implementation of many functions of the Linux kernel. In this experiment, we will learn the basic concepts, principles and implementation techniques of modules, and then use the kernel module to program and access the basic information of the process, thereby deepening our understanding of process concepts and mastering module programming techniques.
(1) Design a module that requires listing the program names, PID numbers, process status and process priorities of all kernel threads in the system.
(2) Design a module with parameters, whose parameters are the PID number of a process. The function of this module is to list the family information of the process, including the program name and PID number of the parent process, brother process and child process.
(3) Please further read the source code implementation of the relevant kernel functions used in the program based on your own situation.
(1) Be familiar with the command interface of linux.
(2) Through the programming application of related system calls for Linux process control, we will further deepen our understanding of process concepts, clarify the connection and differences between processes and programs, and understand the specific meaning of concurrent execution of processes.
(3) Through the use of Linux pipeline communication mechanism, message queue communication mechanism, and shared memory communication mechanism, deepen the understanding of different types of process communication methods.
(4) Deepen the understanding of semaphore synchronization mechanism through the application of Posix semaphores in Linux. (5) Please further read and analyze the kernel source code implementation of related system calls based on your own situation.
(1) Familiar with common Linux commands: pwd, useradd, passwd, who, ps, pstree, kill, top, ls, cd, mkdir, rmdir, cp, rm, mv, cat, more, grep, etc.
(2) Implement a simulated shell:
Write three different programs cmd1.c, cmd2.c, and cmd3.c. The functions of each program are customized and compiled into executable files cmd1, cmd2, and cmd3 respectively. Then write a program to simulate the function of the shell program. It can create a child process for the corresponding command based on the string entered by the user (representing the corresponding command name) and let it execute the corresponding program. The parent process waits for the child process to end, and then waits for the next command to be received. If the received command is exit, the parent process ends; if the received command is an invalid command, "Command not found" is displayed and you continue to wait.
(3) Implement a pipeline communication program:
A pipeline is created by the parent process, and then 3 child processes are created, and these three child processes use the pipeline to communicate with the parent process: the child process sends information, and the parent process and other three child processes receive the information after all sending messages. The specific content of communication can be designed at will according to your own needs, and it is required to test various situations in the blocking reading and writing process, test the default size of the pipeline, and to use the Posix semaphore mechanism to achieve mutually exclusive access to the pipeline between processes. Run the program to observe the actual number of bytes read and write by the process and the process blocking and wake-up under various circumstances.
(4) Use Linux's message queue communication mechanism to realize communication between two threads:
Write a program to create two threads: sender thread and receive thread, where the sender thread runs the function sender(), which creates a message queue, and then loops to wait for the user to enter a string of characters through the terminal, sending the string of characters to the receiver thread through the message queue until the user enters "exit"; finally, it sends a message "end" to the receiver thread, and waits for the receiver's reply. After the reply message, it displays the received reply information on the terminal screen, deletes the relevant message queue, and ends the program's running. The Receiver thread runs receive(), which receives messages from the sender through the message queue and displays the message on the terminal screen until it receives a message with "end". At this time, it sends an answer message "over" to the sender, ending the program's running. Use nameless semaphores to achieve synchronization and mutual exclusion between two threads.
(5) Use Linux's shared memory communication mechanism to realize communication between two processes:
Write a program sender, which creates a shared memory, and then waits for the user to enter a string of characters through the terminal, and sends the string of characters to the receiver through the shared memory; finally, it waits for the receiver's reply. After receiving the reply message, it displays the received reply information on the terminal screen, deletes the shared memory, and ends the program's running. Write a receiver program, which receives messages from the sender through shared memory, displays the message on the terminal screen, and then sends an answer message "over" to the sender through the shared memory, ending the program's running. Use a named semaphore or System V semaphore to achieve mutually exclusive and synchronous use of shared memory by two processes.
Through the management of specific file storage space, the physical structure of files, directory structure and file operations, we will deepen our understanding of the internal data structure, functions and implementation process of the file system.
(1) Open a virtual disk space in memory as a file storage partition, and implement a simple file system in a single user single task system based on multi-level directories. When exiting the file system, the virtual file system should be saved to disk as a file so that it can be restored to the virtual disk space in memory next time.
(2) The allocation of file storage space can be done by explicit link allocation or other methods.
(3) You can choose bit diagrams or other methods to manage free disk space. If bitmap is used to manage file storage space and use explicit link allocation, then bitmap can be merged into FAT.
(4) The file directory structure adopts a multi-level directory structure. For simplicity, index nodes can be used, each directory item should contain information such as file name, physical address, length, etc., and the read and write files can also be protected through directory items.
(5) The following operation commands are required: