Linux process descriptor task_struct

Source: Internet
Author: User
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 task_struct struct in Linux kernel 3.0... 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.
 
Unsigned int rt_priority;
 
 
 
// The list_head struct is displayed here. For details, refer
 
Struct list_head tasks;
 
 
 
// Here the mm_struct structure is displayed, which records the memory usage of the process. for details, see
 
Struct mm_struct * mm;
 
 
 
/* The following are some process status parameters */
Int exit_state;
Int exit_code, exit_signal;
 
 
// Process ID
 
Pid_t pid;
 
 
 
// This is the process group number
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 linked list of the process to obtain the process descriptor of all children. However, list_for_each and list_entry must be used. the list_entry actually uses container_of directly. for details, see
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.
Related Article

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.