A data structure of the Linux kernel--task_struct__html

Source: Internet
Author: User
Tags bit set volatile

In Linux, each process is defined by the TASK_STRUCT data structure. Task_struct is what we usually call the PCB. She is the only means of controlling the process and the most effective means. When we call fork (), the system generates a task_ for us struct structure. It then inherits some data from the parent process, and inserts the new process into the process tree for process management. So understanding the structure of task_struct is critical to our understanding of task scheduling (the same concept for tasks and processes in Linux).

Task_struct:

Process state, the record process is waiting, running, or deadlock scheduling information, which scheduling function scheduling, how to dispatch the communication status of the process because to insert the process tree, you must have a pointer to the parent-child sibling, of course, the task_struct type of time information, such as the calculation of good execution time, so that CPU distribution , decided to change the process attribution can read and write some open file information process context and kernel context processor context memory information because each PCB is the case, only these structures can meet all the requirements of a process. Open./usr/src/kernels/2.6.32-431.el6.i686/include/linux/sched.h (centos6.5) to find the definition of task_struct

struct Task_struct {volatile long state;  Describes whether the process can be executed, or interruptible, etc. unsigned long flags;    Flage is the process number, and an int sigpending is given when the fork () is invoked; Whether the process is pending signal mm_segment_t Addr_limit; Process address space, which distinguishes between the kernel process and the normal process where memory resides,//0-0XBFFFFFFF for User-thead//0-0xffffffff for Kernel-thread//dispatch flags, indicating whether the process needs to be scheduled again,
	If not 0, the dispatch volatile long need_resched occurs when returning from the kernel state to the user state;  int lock_depth;       Lock depth long nice;
	Process of the basic time slice//process scheduling strategy, there are three kinds of real-time process: SCHED_FIFO,SCHED_RR, time-sharing process: sched_other unsigned long policy; struct Mm_struct *mm;
	Process memory management information int processor;
	If the process is not running on any CPU, the value of cpus_runnable is 0, otherwise it is 1 the value is updated unsigned long cpus_runnable when the queue is locked, cpus_allowed; struct List_head run_list;  Pointer to run queue unsigned long sleep_time;
	The sleep time of the process is used to connect all the processes in the system into a two-way cyclic list, the root of which is init_task struct task_struct *next_task, *prev_task;
	struct Mm_struct *active_mm;       struct List_head local_pages;
	Point to local page unsigned int allocation_order, nr_local_pages;  struct LINUX_BINFMT *binfmt;
The format of the executable file that the process is running int exit_code, exit_signal;	int pdeath_signal;
	Parent process termination is a signal sent to a subprocess unsigned long personality; 
	Linux can run IBCS2-compliant program int did_exec:1 generated by other Unix operating systems;    pid_t pid;   Process identifier, which is used to represent a process pid_t pgrp;  Process group identification that represents the process group pid_t TTY_OLD_PGRP to which the process belongs;  The group identifier of the Process control Terminal pid_t session;
	Session identification of the process pid_t tgid;     int leader;
	Indicates whether the process is the session manager struct Task_struct *p_opptr,*p_pptr,*p_cptr,*p_ysptr,*p_osptr;   struct List_head thread_group; Line Cheng struct task_struct *pidhash_next;
	Used to link a process into a hash table struct task_struct **pidhash_pprev;  wait_queue_head_t Wait_chldexit;  For WAIT4 () using struct completion *vfork_done; For vfork () using unsigned long rt_priority; Real-time priority, using it to calculate real-time process scheduling of the weight value//IT_REAL_VALUE,IT_REAL_INCR for real timer, unit for jiffies, the system according to It_real_value//set timer of the first termination time.
	When the timer expires, send the SIGALRM signal to the process, at the same time, according to//IT_REAL_INCR reset termination time, IT_PROF_VALUE,IT_PROF_INCR for profile timer, unit for jiffies.
	When the process runs, no matter in what state, each tick makes the It_prof_value value minus one, and when it is reduced to 0 o'clock, send//signal sigprof to the process and reset the time according to IT_PROF_INCR. It_virt_value,it_virt_value is used for the virtual timer, the unit is jiffies. When the process is running, no matter in what//state, each TIck the It_virt_value value minus one when it's reduced to 0 o'clock, sending a signal to the process SIGVTALRM, resetting the initial value according to//IT_VIRT_INCR.
	unsigned long it_real_value, It_prof_value, It_virt_value;
	unsigned long it_real_incr, IT_PROF_INCR, It_virt_value;   struct Timer_list real_timer;      Pointer to real-time timer struct TMS times;  Record the time consumed by the process unsigned long start_time; 
	Process creation time//record the user state time consumed by the process on each CPU and the kernel mentality time long per_cpu_utime[nr_cpus], Per_cpu_stime[nr_cpus]; Memory page faults and exchange information://min_flt, Maj_flt Cumulative process of the number of secondary pages (Copy on write and anonymous pages) and the number of main page faults (from the mapping file or Exchange//device read the number of pages), Nswap record process cumulative number of pages,
	That is, the number of pages written to the swap device.
	Cmin_flt, Cmaj_flt, Cnswap records the cumulative number of page faults in the process for all descendants of the ancestors, the number of main pages and number of pages swapped out.
	When the parent process reclaims aborted child processes, the parent process accumulates this information for the child process into these domains of its own structure unsigned long min_flt, Maj_flt, Nswap, Cmin_flt, Cmaj_flt, Cnswap; int swappable:1; Indicates whether the virtual address space of the process is allowed to be swapped//process authentication information//uid,gid The user identifier and group identifier of the user running the process, usually the Uid,gid//euid,egid of the process creator as valid Uid,gid//fsuid,
	Fsgid for file system Uid,gid, these two ID numbers are usually equal to valid uid,gid, and they are used when checking access rights to files//systems.
	Suid,sgid for backup Uid,gid uid_t Uid,euid,suid,fsuid;
	gid_t Gid,egid,sgid,fsgid; int ngroups; Record how many user groups the process gid_t GrouPs[ngroups];
	The power of the group//process in which the process is recorded is a valid bit set, a collection of inherited bits, a set of allowed bits kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
	int keep_capabilities:1;
	struct User_struct *user;  struct Rlimit rlim[rlim_nlimits];   Resource restriction information associated with the process unsigned short used_math;   Whether to use the FPU char comm[16];
	The process is running executable file name//file system Information int link_count, total_link_count;
	Null if no TTY process is located in the control terminal, if you do not need to control the terminal, then the pointer is empty struct tty_struct *tty;
	unsigned int locks;  Inter-process communication information struct Sem_undo *semundo; The process of all undo operations on the signal lights struct sem_queue *semsleeping;
	When a process is suspended because of a semaphore operation, he records the CPU state of the pending operation//process in the queue, and when switching, save to the task_struct of the stop process struct thread_struct thread;
	File system Information struct fs_struct *fs;
	Open file information struct files_struct *files;
	Signal processing function spinlock_t Sigmask_lock; struct Signal_struct *sig;  Signal processing function sigset_t blocked;  The process is currently blocking the signal, each signal corresponding to a struct sigpending pending;
	Whether the signal to be processed on the process is unsigned long sas_ss_sp;
	size_t Sas_ss_size;
	Int (*notifier) (void *priv);
	void *notifier_data;
	sigset_t *notifier_mask;
	U32 parent_exec_id; U32 self_exec_id;
	spinlock_t Alloc_lock;
void *journal_info; };

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.