Analysis of Linux process management: Creating, Managing, scheduling, and destroying

Source: Internet
Author: User

Introduction: The principles involved in the creation and management of linux® user space processes have a lot in common with UNIX®, but there are some unique features that are specific to Linux. In this article, understand the lifecycle of the Linux process, and explore the inner workings of user process creation, memory management, scheduling, and destruction.

Linux is a dynamic system that adapts to changing computing needs. The performance of Linux computing requirements is centered on the general abstraction of the process. A process can be a short term (a command executed from the command line), or it can be a long term (a network service). Therefore, the general management of the process and its scheduling is very important.

In user space, processes are represented by process identifiers (PID). From the user's point of view, a PID is a numeric value that uniquely identifies a process. A PID is not changed throughout the life of a process, but the PID can be reused after the process is destroyed, so caching them is not always ideal.

In user space, there are several ways to create a process. You can execute a program (which can lead to the creation of a new process), or you can call a fork or exec system call within a program. Fork calls cause a child process to be created, while the exec call replaces the current process context with a new program. Next, I'll discuss these methods so that you can understand how they work.

In this article, I'll start with a description of the process in the following order, first showing the kernel representations of the processes and how they are managed within the kernel, then look at the various ways in which processes are created and scheduled (on one or more processors), and finally the destruction of the process.

Process representation

Within the Linux kernel, processes are represented by a fairly large structure called task_struct. This structure contains all the data necessary to represent this process, and also contains a large amount of other data for statistics (accounting) and maintenance of relationships with other processes (parent and child). A complete introduction to Task_struct is beyond the scope of this article, and Listing 1 gives a small part of the task_struct. The code contains the specific elements to explore in this article. Task_struct is located in./linux/include/linux/sched.h.

Listing 1. A small part of the task_struct

struct Task_struct {
volatile long state;
void *stack;
unsigned int flags;
int Prio, Static_prio;
struct List_head tasks;
struct mm_struct *mm, *active_mm;
pid_t pid;
pid_t Tgid;
struct task_struct *real_parent;
Char Comm[task_comm_len];
struct thread_struct thread;
struct files_struct *files;
...
};

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.