Linux Process descriptor task_struct

Source: Internet
Author: User
Tags benchmark ranges

From: http://blog.csdn.net/hongchangfirst/article/details/7075026

Everyone knows about processes. But do you know how Linux manages processes? Each process has a process descriptor, specifically the information stored in the task_struct struct, in Linux/sched. in the H file, Let's first look at the definition of the task_struct struct in Linux kernel 3.0 (delete unnecessary fields and only keep important fields ). At the same time, you are welcome to repost and exchange ideas.

Struct task_struct {

// This is the running state of the process.-1 indicates that the process is not running, 0 indicates that the process is running, and> 0 indicates that the process is stopped.
Volatile long state;

/*

Flags indicates the current status of a process, for example:

0x00000002 indicates that the process is being created;

0x00000004 indicates that the process is about to exit;

0x00000040 indicates that the process is fork, but exec is not executed;

0x00000400 indicates that the process is killed because other processes send signals.

*/

Unsigned int flags;

// Indicates the running priority of the process. PRIO indicates the dynamic priority. According to static_prio and interactive rewards and punishments, static_prio indicates the static priority of the process and is determined during process creation, the value ranges from-20 to 19. The smaller the value, the higher the priority.

Int Prio, static_prio, normal_prio;

// The list_head struct is displayed here. For more information, see the http://blog.csdn.net/hongchangfirst/article/details/7076225.

Struct list_head tasks;

// Here the mm_struct structure, the structure records the memory usage of the process, please refer to the http://blog.csdn.net/hongchangfirst/article/details/7076207 for details

Struct mm_struct * mm;

/* The following are some Process status parameters */
Int exit_state;
Int exit_code, exit_signal;

// This is the process number maintained by the kernel. in Linux, the thread is implemented by the process, and the process number you see is the tgid domain.

Pid_t PID;

// This is the thread group number, which is consistent with the process Number of the lead process in the thread group. The tgid value is actually returned when getpid () is called in the user program.
Pid_t tgid;

// Real_parent is the "biological father" of the process, regardless of whether it is "foster care ".

Struct task_struct * real_parent;

// Parent is the current parent process of the process, which may be the "stepfather"
Struct task_struct * parent;

// Here children refers to the child process linked list, you can get all child process descriptor, but need to use list_for_each and list_entry, list_entry actually directly uses container_of, For details, see http://blog.csdn.net/hongchangfirst/article/details/7076225
Struct list_head children;

// Similarly, sibling is the linked list of the brother of the process, that is, the linked list of all the children of his father. Similar to children.

Struct list_head sibling;

// This is the process descriptor of the main thread. You may wonder why the thread is represented by the process descriptor because Linux does not implement the relevant structure of the thread separately, simply use a process to replace the thread and then perform some special processing on it.

Struct task_struct * group_leader;

// This is the linked list of all threads of the process.

Struct list_head thread_group;

// As the name implies, This is the CPU time used by the process. utime is the execution time in the user State, and stime is the execution time in the kernel state.

Cputime_t utime, stime;

// The following is the start time, but the time benchmark is different.
Struct timespec start_time;

Struct timespec real_start_time;

// Comm is an array of characters that saves the name of the process. The maximum length is 15 because task_comm_len is 16.

Char comm [task_comm_len];

/* File System Information count */
Int link_count, total_link_count;

/* The status of the process under a specific CPU */
Struct thread_struct thread;

/* Structure of file system information */
Struct fs_struct * FS;

/* Structure of opened file information */
Struct files_struct * files;

/* Handle of signal-related information */
Struct signal_struct * signal;
Struct sighand_struct * sighand;

/* These are relaxation time values used to specify the timeout time for select () and Poll (), in the unit of nanoseconds */
Unsigned long timer_slack_ns;
Unsigned long default_timer_slack_ns;

};

Here, we have seen many fields, but these fields are only the tip of the iceberg of task_struct. I hope more people will think that we will unveil the mystery of task_struct. For memory descriptors, see http://blog.csdn.net/hongchangfirst/article/details/7076207.

Reprinted please indicate the source:

Original article: http://blog.csdn.net/hongchangfirst/article/details/7075026

Author: hongchangfirst


Everyone knows about processes. But do you know how Linux manages processes? Each process has a process descriptor, specifically the information stored in the task_struct struct, in Linux/sched. in the H file, Let's first look at the definition of the task_struct struct in Linux kernel 3.0 (delete unnecessary fields and only keep important fields ). At the same time, you are welcome to repost and exchange ideas.

Struct task_struct {

// This is the running state of the process.-1 indicates that the process is not running, 0 indicates that the process is running, and> 0 indicates that the process is stopped.
Volatile long state;

/*

Flags indicates the current status of a process, for example:

0x00000002 indicates that the process is being created;

0x00000004 indicates that the process is about to exit;

0x00000040 indicates that the process is fork, but exec is not executed;

0x00000400 indicates that the process is killed because other processes send signals.

*/

Unsigned int flags;

// Indicates the running priority of the process. PRIO indicates the dynamic priority. According to static_prio and interactive rewards and punishments, static_prio indicates the static priority of the process and is determined during process creation, the value ranges from-20 to 19. The smaller the value, the higher the priority.

Int Prio, static_prio, normal_prio;

// The list_head struct is displayed here. For more information, see the http://blog.csdn.net/hongchangfirst/article/details/7076225.

Struct list_head tasks;

// Here the mm_struct structure, the structure records the memory usage of the process, please refer to the http://blog.csdn.net/hongchangfirst/article/details/7076207 for details

Struct mm_struct * mm;

/* The following are some Process status parameters */
Int exit_state;
Int exit_code, exit_signal;

// This is the process number maintained by the kernel. in Linux, the thread is implemented by the process, and the process number you see is the tgid domain.

Pid_t PID;

// This is the thread group number, which is consistent with the process Number of the lead process in the thread group. The tgid value is actually returned when getpid () is called in the user program.
Pid_t tgid;

// Real_parent is the "biological father" of the process, regardless of whether it is "foster care ".

Struct task_struct * real_parent;

// Parent is the current parent process of the process, which may be the "stepfather"
Struct task_struct * parent;

// Here children refers to the child process linked list, you can get all child process descriptor, but need to use list_for_each and list_entry, list_entry actually directly uses container_of, For details, see http://blog.csdn.net/hongchangfirst/article/details/7076225
Struct list_head children;

// Similarly, sibling is the linked list of the brother of the process, that is, the linked list of all the children of his father. Similar to children.

Struct list_head sibling;

// This is the process descriptor of the main thread. You may wonder why the thread is represented by the process descriptor because Linux does not implement the relevant structure of the thread separately, simply use a process to replace the thread and then perform some special processing on it.

Struct task_struct * group_leader;

// This is the linked list of all threads of the process.

Struct list_head thread_group;

// As the name implies, This is the CPU time used by the process. utime is the execution time in the user State, and stime is the execution time in the kernel state.

Cputime_t utime, stime;

// The following is the start time, but the time benchmark is different.
Struct timespec start_time;

Struct timespec real_start_time;

// Comm is an array of characters that saves the name of the process. The maximum length is 15 because task_comm_len is 16.

Char comm [task_comm_len];

/* File System Information count */
Int link_count, total_link_count;

/* The status of the process under a specific CPU */
Struct thread_struct thread;

/* Structure of file system information */
Struct fs_struct * FS;

/* Structure of opened file information */
Struct files_struct * files;

/* Handle of signal-related information */
Struct signal_struct * signal;
Struct sighand_struct * sighand;

/* These are relaxation time values used to specify the timeout time for select () and Poll (), in the unit of nanoseconds */
Unsigned long timer_slack_ns;
Unsigned long default_timer_slack_ns;

};

Here, we have seen many fields, but these fields are only the tip of the iceberg of task_struct. I hope more people will think that we will unveil the mystery of task_struct. For memory descriptors, see http://blog.csdn.net/hongchangfirst/article/details/7076207.

Reprinted please indicate the source:

Original article: http://blog.csdn.net/hongchangfirst/article/details/7075026

Author: hongchangfirst


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.