Linux-based process analysis

Source: Internet
Author: User

Tag: kernel ble roc SM waits for event signal storage to get processed

What is a process?

A process is an instance of program execution and a migration process for a finite state machine. The difference between process and procedure: dynamic and static;

Related processes of WINDOWS10

List all running/active processes with Ps-a in Linux

Using the top command in Linux, you can monitor the resources used by different processes. (including: PID, priority,%cpu,%memory, etc.)

Process Run Process:

Creation of processes

User space can be used to create a process by executing a program, or calling a fork (or exec) system call within a program, which causes a child process to be created, and the exec call replaces the current process context with the new program. The birth of a new process can also be passed vfork () and Clone () respectively. The fork, Vfork, and clone three user-state functions are provided by the LIBC Library, which calls Fork,vfork and clone, respectively, from the same name as the Linux kernel provides. The following is an example of a fork system call.

The end result is a direct call to Do_fork. The function hierarchy created by the process is as follows:

You can see that do_fork is the basis for process creation. You can find the Do_fork function (as well as the cooperative function copy_process) within the./linux/kernel/fork.c.

The code is as follows:

(1) Before the System_call function executes, the CPU control unit has automatically saved the values of the EFlags, CS, EIP, SS, and ESP registers to the corresponding kernel stack of the process. Subsequently, the system call number stored in the EAX register is pressed into the stack first within the System_call. Then execute the Save_all macro. The macro saves all CPU registers that are likely to be used by the next system call in the stack.
(2) Obtain the address of the THREAD_INOF structure of the current process by Get_thread_info macro, and then detect if the current process is being tracked by another process (for example, when debugging a program, the program being debugged is in a tracked state), that is Thread_ The _tif_allwork_mask of the flag field in the info structure is set to 1. If a tracked situation occurs, turn to the processing command at the syscall_trace_entry mark.
(3) Check the legality of the system call number passed over by the user state process. If it is not legal, it jumps to the command at the SYSCALL_BADSYS flag.
(4) If the system call is legitimate, look for the system invocation number in the system call Table sys_call_table, locate the corresponding function entry point, and jump into the sys_./linux/arch/x86/kernel/syscall_table_32.s Fork this service routine. Because the table entries in the Sys_call_table table are 4 bytes, the specific way to get a service routine pointer is to multiply the system call number Saved by EAX by 4, and then add the base address of the sys_call_table table. The code in SYSCALL_TABLE_32.S is as follows:

Process scheduling:

The created process is eventually inserted into the run queue, which is dispatched through the Linux scheduler. The Linux Scheduler maintains a set of lists for each priority level, where task_struct references are saved. When the running process time slice is exhausted, the clock tick interrupts, calling the Kernel/sched.c:scheduler_tick () Process Scheduler interrupt processing, the interrupt is returned after the call schedule (). Tasks in the run queue are invoked through the schedule function (within./linux/kernel/sched.c), which determines the best process based on the load and process execution history.

Process destruction:

Process Status:

R running State (running): Indicates that the process is either running or running in the queue

S sleep state (sleeping): means that the process is waiting for the event to complete, and this sleep is also called an interruptible sleep

D Disk Sleep Status: This state of sleep is usually waiting for the end of I/O, also known as non-disruptive sleep

T stop State (stopped): Can send sigstop signal to process, let process stop. You can also send a sigcont signal to keep the process running.

X Dead State (dead): This state is just a return state, you will not see this state in the task list

Z Zombie Status (Zombie): The child process exits, the parent process does not read the child process's exit code, the child process enters the Z state

Linux is still evolving, and one of the areas that needs to be further innovated and optimized is process management. While adhering to the UNIX principle, Linux is also constantly breaking through. New processor architectures, symmetric multi-processing (SMP), and virtualization will all lead to new developments in the nuclear field. An example of this is the new O (1) scheduler introduced in Linux version 2.6, which provides scalability for systems with a large number of tasks.

Linux-based process analysis

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.