1. Process Concept
A process is a run-time activity of a program with independent functionality about a data collection. It can apply and own system resources, is a dynamic concept, is an active entity. It is not just the code of the program, it also includes the current activity, which is represented by the value of the program counter and the contents of the processing register.
Introduction to 2.linux Systems
Linux is known for its efficiency and flexibility, and the modular design of Linux allows it to operate on expensive workstations as well as all UNIX features on inexpensive PCs, with multi-tasking and multi-user capabilities. Linux is obtained free of charge under the GNU Public License and is a POSIX compliant operating system. Linux operating system packages include not only the full Linux operating system, but also the text editor, high-level language compiler and other application software. It also includes a x-windows graphical user interface with multiple window managers, as we do with Windows NT, allowing us to manipulate the system using Windows, icons, and menus.
3.linux How to organize processes3.1 Status of the process
When the process executes, it changes state depending on the situation. Process state is the basis for scheduling and swapping.
①r (task_running): Executable Status/Run state
②s (task_interruptible): interruptible sleep state
③ D (task_uninterruptible): Non-interruptible sleep status
⑤t (task_stopped or task_traced): Pause or Trace status
⑥z (Task_dead-exit_zombie): Exit status, Process becomes zombie process
3.2 Process scheduling information
The scheduler uses this information to determine which process in the system should run most.
Need_resched Dispatch flag (next scheduling opportunity)
Nice static priority (process time slice)
Counter Dynamic Priority (remaining time slices)
Policy scheduling policies
Rt_priority Real-time priority (only meaningful for real-time processes)
3.3 Process Identifiers
is used to identify different processes, so the process identifier is introduced.
Pid process specifier
Uid, Gid user representation, group identifier
Euid, egid Valid user identifier, valid group identifier
Suid, sGid Backup user identifiers, backup group identifiers
Fsuid, Fsgid file system user identifiers, file system group identifiers
3.4 How the process is organized
3.4.1current Macro
When the process executes on the CPU, the kernel obtains a pointer to the process task_struct through current
This is an architecture-related code:
static struct task_struct *get_current (void) { struct Task_struct *current; __asm__ ("":"=r""0" (~8191UL)); return current;}
3.4.2 Bidirectional Loop List
The Prev_task and Next_task domains in each process task_struct structure are used to implement this list.
The head and tail of the list are Init_task, which corresponds to process 0 (PID 0), which is known as an empty process, which is the ancestor of all processes.
3.4.3 Run queue
Run Queue when the kernel is looking for a new process to run on the CPU, it must consider only the processes that are in a running state (that is, the process in the task_running state), because scanning the entire process list is quite inefficient, So the two-way cyclic linked list of the running state process is introduced, also called the run queue.
The queue is maintained by a list of two pointers run_list in the task_struct structure. There are two flags for the queue: one is the "empty process" idle_task; the other is the length of the queue, which is the number of processes in the system that are in the operational state (task_running), represented by a global integer variable nr_running.
3.4.4 Waiting Queue
The wait queue process must often wait for certain events to occur, such as waiting for a disk operation to terminate, waiting for the system resource to be freed, or waiting time to pass through a fixed interval. Wait for the queue to implement conditional waits on the event, that is, the process that wants to wait for a particular event puts itself in the appropriate waiting queue and discards control. Therefore, the wait queue represents a set of sleep processes that are awakened by the kernel when a condition becomes true. The wait queue is implemented by a circular list.
3.5 Status Transition diagram for a process
4, the process of scheduling 4.1 first to first service scheduling algorithm
First come first service (FCFS) scheduling algorithm is the simplest scheduling algorithm, which can be used for both job scheduling and process scheduling. When this algorithm is used in job scheduling, each schedule selects one or more jobs that first enter the queue from the fallback job queue, puts them into memory, assigns them resources, creates processes, and then puts them in the ready queue. When the FCFS algorithm is used in the process scheduling, each schedule is to select a process from the ready queue that is first entered into the queue, assigning the processor to it and putting it into operation. The process has been running until it has completed or an event has been blocked before discarding the processor.
4.2. Priority scheduling Algorithm
In the priority scheduling algorithm, each process is associated with a priority, and the kernel assigns the CPU to the highest-priority process. Processes with the same priority are dispatched in accordance with the principle of first-come-first service. Assuming that the execution time and priority of the process are as follows, and that these processes exist in memory at the same time, a priority-based scheduling algorithm is adopted to consider the process starvation problem, because high-priority processes are always prioritized, and low-priority processes may never be executed by the kernel. Aging is a solution to this problem, so-called Aging refers to the gradual improvement of the system in the long-awaited process priority. For example, if the priority range is from 127 to 0 (127 for the lowest priority), then we can add 1 to the priority of the process every 15 minutes. Eventually, even a process with the lowest priority of 127 becomes the highest-priority process in the system and is executed.
4.3. Short process Priority
Shortest CPU run-time priority scheduling algorithm (Scbf--shortest CPU Burst first) the algorithm selects the next "CPU execution period shortest" process from the ready queue and assigns the processor to it. The shortest job priority scheduling is a special case of priority scheduling. In priority scheduling, we schedule according to the priority of the process, in the shortest job priority scheduling we are based on the duration of the execution of the job scheduling.
4.4.CFS Scheduling algorithm
The concept of the All-Fair Scheduler (CFS) is to model an ideal, accurate multitasking CPU on a real hardware. The ideal CPU model runs at 100% load, runs each task in parallel at a precise and equal speed, and each task runs at 1/n speed, that is, the ideal CPU has n tasks running, and the speed of each task is 1/n of the entire CPU load.
Because on real hardware, only one task can be run at a time, this introduces the concept of virtual runtime, which is the next time slice (TimeSlice) that a task executes on an ideal CPU model. In fact, the virtual run time of a task takes into account the actual run time of the total number of running tasks.
The main idea behind CFS is to maintain a balance (fairness) in providing processor time for the task. CFS in order to embody the fairness manifested in 2 aspects
(1) The running time of the process is equal
(2) The process of sleep is compensated
The following is the scheduling class
Static Const structSched_class Fair_sched_class ={. Next= &Idle_sched_class,. Enqueue_task=Enqueue_task_fair,. Dequeue_task=Dequeue_task_fair,. Yield_task=Yield_task_fair,. Check_preempt_curr=check_preempt_wakeup,. Pick_next_task=Pick_next_task_fair,. Put_prev_task=Put_prev_task_fair, #ifdef CONFIG_SMP. Select_task_rq=Select_task_rq_fair,. Load_balance=Load_balance_fair,. Move_one_task=Move_one_task_fair,. Rq_online=Rq_online_fair,. Rq_offline=Rq_offline_fair,. task_waking=Task_waking_fair,#endif . Set_curr_task=Set_curr_task_fair,. Task_tick=Task_tick_fair,. Task_fork=Task_fork_fair,. prio_changed=Prio_changed_fair,. Switched_to=Switched_to_fair,. Get_rr_interval=Get_rr_interval_fair, #ifdef config_fair_group_sched. Task_move_group=Task_move_group_fair,#endif };
Function description
Enqueue.task: When a task enters a running state, the function is called. It puts the dispatch entity (process) into the red-black tree and adds 1 to the nr_running variable.
Dequeue.task: Called when a task exits the operational state, it removes the corresponding dispatch entity from the red-black tree and minus 1 from the nr_running variable.
Yield_task: In the case of Compat_yield sysctl shutdown, the function actually executes the queue after first out, in which case it places the dispatch entity on the right-most side of the red-black tree.
check.preempt Curr: This function checks whether the currently running task is preempted. The CFS Scheduler module performs a fairness test until the running task is actually preempted. This will drive the wake-up (wakeup) preemption. Pick_next_task: This function selects the most appropriate process to run next.
load_balance: Each scheduler module implements two functions, Load_balance_start () and Load_balance_next (), using these two functions to implement an iterator that is called in the module's load balance routine. The kernel scheduler uses this method to implement load balancing of processes managed by the dispatch module.
Set_curr_task: This function is called when a task modifies its dispatch class or modifies its task group.
task_ Tick: This function is usually called from the time tick function; it may cause the process to switch. This will drive the runtime (running) preemption.
task NEW: The kernel scheduler provides the scheduling module with the opportunity to manage the startup of new tasks. The CFS dispatch module uses it for group scheduling, while the scheduling module for real-time tasks does not use this function.
5. Personal Thoughts
Linux has many advantages as an open source system
① Open source, you can let everyone on the system to develop at will, design their own needs of the system.
② security, provides a large number of network management software, network security software
③ extensive hardware support to run flawlessly on today's mainstream processors
However, he did not have a friendly graphical interface windous, for beginners need to learn more command, so need to have a long study time to be familiar with the use.
eg
Https://www.aliyun.com/jiaocheng/158665.html
7894211
Http://www.cnblogs.com/hanxiaoyu/p/5576277.html
Http://www.cnblogs.com/yangjiannr/p/Linux-jin-cheng-zhuang-tai.html
Analyzing the Linux process model