Linux Process Management descriptor task_struct, linuxtask_struct
Turn: 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 ).
1 struct task_struct {2 // 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. 3 volatile long state; 4/* 5 flags indicates the current state of the process. For example, 6 0x00000002 indicates that the process is being created. 7 0x00000004 indicates that the process is preparing to exit; 8 0x00000040 indicates that the process is fork, but exec is not executed; 9 0x00000400 indicates that the process is killed because other processes send signals. 10 */11 unsigned int flags; 12 // 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, when the process is created, the value ranges from-20 to 19. The smaller the value, the higher the priority. 13 int prio, static_prio, normal_prio; 14 // The list_head struct is displayed here. For details, see the http://blog.csdn.net/hongchangfirst/article/details/707622515 struct list_head tasks; 16 // here the mm_struct struct is displayed, this struct records the memory usage of the process. For details, refer to the http://blog.csdn.net/hongchangfirst/article/details/707620717 struct mm_struct * mm; 18/* and then some state parameters of the process */19 int exit_state; 20 int exit_code, exit_signal; 21 // process number. Note that this is the process number maintained by the kernel. in Linux, the thread is implemented by the process. Is the tgid domain. 22 pid_t pid; 23 // 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. 24 pid_t tgid; 25 // real_parent is the "biological father" of the process, regardless of whether it is "foster care ". 26 struct task_struct * real_parent; 27 // parent is the current parent process of the process. It may be the "stepfather" 28 struct task_struct * parent; 29 // 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 more information, see http://blog.csdn.net/hongchangfirst/article/details/707622530 struct list_head children; 31 // Similarly, sibling the linked list of this process brother, that is, the list of all the children of his father. Similar to children. 32 struct list_head sibling; 33 // This is the process descriptor of the main thread. Maybe you may wonder why the thread is represented by the process descriptor because linux does not implement the relevant struct of the thread separately, simply use a process to replace the thread and then perform some special processing on it. 34 struct task_struct * group_leader; 35 // This is the linked list of all threads of the process. 36 struct list_head thread_group; 37 // as the name suggests, 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. 38 cputime_t utime, stime; 39 // The following is the start time, but the time benchmark is different. 40 struct timespec start_time; 41 struct timespec real_start_time; 42 // comm is the character array that saves the name of the process. The maximum length is 15 because TASK_COMM_LEN is 16. 43 char comm [TASK_COMM_LEN]; 44/* File System Information count */45 int link_count, total_link_count; 46/* Status of the process under a specific CPU */47 struct thread_struct thread; 48/* structure of File System related information */49 struct fs_struct * fs; 50/* structure of opened file related information */51 struct files_struct * files; 52/* handle of signal-related information */53 struct signal_struct * signal; 54 struct sighand_struct * sighand; 55/* These are relaxation time values used to specify select () and poll () the timeout time in the unit of nanoseconds */56 unsigned long timer_slack_ns; 57 unsigned long default_timer_slack_ns; 58 };