ext.:http://blog.csdn.net/hongchangfirst/article/details/7075026
Everyone knows the process, but how does Linux manage its processes? Each process has a process descriptor, specifically TASK_STRUCT structure storage related information, in the Linux/sched.h file definition, then we first look at the Linux Kernel 3.0 version of the definition of the TASK_STRUCT structure (delete unnecessary fields, Only important fields are retained).
1 structtask_struct {2 //This is the run-time state of the process, 1 means not running, 0 is operational, and the >0 representative has stopped. 3 volatile LongState ;4 /*5 flags are the current status flags of the process, as specific as: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 was forked out, but did not execute exec;9 0x00000400 indicates that the process was killed because other processes sent related signals. Ten */ OneUnsignedintflags; A //represents the run priority of this process, prio represents a dynamic priority, is calculated based on Static_prio and interactivity, Static_prio is the static priority of the process, determined at process creation, ranging from 20 to 19, the smaller the priority. - intPrio, Static_prio, Normal_prio; - //The List_head structure appears here, please refer to HTTP for details://blog.csdn.net/hongchangfirst/article/details/7076225 the structlist_head tasks; - //There is a mm_struct structure, which records the use of process memory, please refer to HTTP for details://blog.csdn.net/hongchangfirst/article/details/7076207 - structMm_struct *mm; - /*Next is some state parameters of the process*/ + intexit_state; - intExit_code, exit_signal; + //This is the process number, note that this is the process number that the kernel maintains itself, because the thread in Linux is implemented by the process, and the process number that the user sees is the Tgid domain. A pid_t pid; at //This is the thread group number, and the process number of the lead process in the thread group is consistent, and we call Getpid () in the user program actually returns the Tgid value. - pid_t Tgid; - //Real_parent is the "biological father" of the process, whether or not it is "foster care". - structTask_struct *real_parent; - //The parent is the process now, and it is possible that the "stepfather" - structTask_struct *parent; in //here children refers to the process of the child's list, you can get all the child's process descriptor, but need to use List_for_each and list_entry,list_entry actually directly use container_of, for details, refer to the HTTP ://blog.csdn.net/hongchangfirst/article/details/7076225 - structlist_head Children; to //In the same vein, sibling the linked list of the Process brothers, which is the list of all the children of their fathers. Usage is similar to children. + structlist_head sibling; - //This is the process descriptor of the main thread, and perhaps you might wonder why the thread is represented by the process descriptor, because Linux does not implement the thread-related structure individually, but instead uses a process to replace the thread and then do some special processing on it. the structTask_struct *Group_leader; * //This is the list of threads that the process is wired to. $ structList_head Thread_group;Panax Notoginseng //As the name implies, this is the information that the process uses for CPU time, Utime is the time that is executed in the user state, and stime is the execution time in the kernel state. - cputime_t utime, stime; the //The following is the start time, but the time benchmark is not the same. + structTimespec start_time; A structTimespec real_start_time; the //COMM is a character array that holds the name of the process for a maximum length of 15, because Task_comm_len is 16. + CharComm[task_comm_len]; - /*File System Information Count*/ $ intLink_count, Total_link_count; $ /*The status of the process under a specific CPU*/ - structthread_struct thread; - /*file system related information structure*/ the structFs_struct *FS; - /*Open File-related information structure body*/Wuyi structFiles_struct *files; the /*handle to signal-related information*/ - structSignal_struct *signal; Wu structSighand_struct *Sighand; - /*These are slack time values that specify the time-out for Select () and poll (), in nanoseconds nanoseconds*/ AboutUnsignedLongTimer_slack_ns; $UnsignedLongDefault_timer_slack_ns; -};
Process Management Descriptor Task_struct