The characteristics of multiple users in Linux

Source: Internet
Author: User

When studying Linux systems, we often see the word "multi-user". Do you understand the characteristics of multiple users in Linux systems? This section describes the features of multiple users in Linux. Multiple users mean that system resources can be used by different users, that is, each user has specific permissions on their own resources, such as files and devices, without affecting each other. Therefore, the multi-user feature has become an important standard for measuring the operating system quality. How to ensure the fair use of the system has become a problem that must be considered by system designers.

To implement multi-user features, the Linux system divides the life cycle of processes into four states:
1) The process is being executed in user mode;

2) The process is being executed in the core State;

3) The process is not being executed, but it is ready-once the scheduler selects it, it can be put into operation. Many processes can be in this state, and the scheduling algorithm determines which process will become the next execution process;

4) The process is sleeping.

The conversion of the four States is not arbitrary, but a directed graph. The status transition diagram is as follows:

Because a processor can only execute one process at any time, at most one process can be in the first and second states. These two States correspond to two execution states: User State and core state. These two levels mainly protect the system. The core State can execute some privileged commands and enter the user State, while the user State cannot. The division of core and user States ensures the multi-user features of Linux.

Most system calls in Linux are included in the Linux libc library. These system calls can be called through the libc call method. Therefore, when a user process needs to use system resources, such as files, display outputs, and printer outputs ), the function in the Standard C function library is called to implement the corresponding functions, such as opening the file open and printf for display output ). There are two methods to activate a system call: system_call function and lcall7 call gate ). Another kind of syscall function is implemented by calling lcall7, so it is not counted as a unique method. For internal code, system_call is the entry point for all system calls. lcall7 is used to support iBCS2Inter binary compatibility standard version 2, which is not discussed here ). The user Process Activates system_call through libc. This libc will load the parameters you want to pass into the CPU register and trigger 0x80 software interruption, that is, Int $0x80. This process checks the system call number, which tells the kernel process which service to request. Then, it looks at the system call table (sys_call_table) and finds the called kernel function entry address. Then, call the function to complete the corresponding function, wait for the return, do some system checks, and finally return to the process or to other processes, if the process time is exhausted ). This is the overall process of system calls by user processes.

In a time-sharing system such as Linux, several processes can be simultaneously performed, and they may all be called by the system. The kernel will protect the running consistency in the core State by disabling any context switching and controlling the interruption. The kernel allows context switching only when the process is transferred from the "core State running" to the "Sleeping in memory" state. Processes running in the core State cannot be preemptible by other processes. Therefore, the kernel is sometimes called non-preemptive that cannot be preemptible. Even though the kernel does not preemptible processes in the user State. Because the data before processing the system call is prepared, no deadlock occurs during the system call process. Because the kernel is not in the preemptive status, the kernel can maintain its Data Structure consistency, thus solving the mutex mutual exclusion problem-ensure that at most one process executes the critical code at any time.

For example, three user processes A, B, and C are used to call functions simultaneously. When a process is sleeping, the critical zone is locked. At any time, only one process can be executed. It finds that the critical section is locked and waits for the event in which the critical section is locked. Finally, the lock in the critical section is unlocked, and all the waiting processes are awakened and "ready. The kernel finally selects a process such as B) for execution. Process B finds that the critical zone is in the unlocked state, so it locks the critical zone and continues to execute. If process B goes to sleep again before unlocking the critical zone, for example, waiting for the completion of the I/O operation), other processes are scheduled to run in the nuclear energy system. If process A is selected, and process A finds that the critical zone is locked, it goes to sleep again. Process C does the same thing. Finally, process B wakes up and unlocks the buffer, allowing process A to also allow Process C to save the buffer. Therefore, it ensures that at most one process can access resources. During this period, the process of sleep and awakening should be considered as "Atomic": A process enters the sleep state instantaneously and stays there until it is awakened. After sleep, the kernel schedules another process to run and switches the context of the latter. It can be seen that at any time, only one process is executing in the critical section.

In general, the key to implementing multi-user features in Linux is to transfer all system calls to the core State through the system_call interface after data is ready. The core State performs permission check and control, it also ensures exclusive access to resources. On the surface, system calls are the same as other function calls. As long as the results meet the expected conditions, the application cannot determine whether the kernel is actually used, in this way, the core mode switching is transparent to the user layer. This process ensures that each user process does not affect each other's resource operations. This achieves the multi-user features of Linux.

I hope this article will be helpful for you to introduce the features of multiple users in Linux.

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.