background: in order to manage processes, the operating system must clearly describe what each process does, and for this reason, the operating system uses several
The
structure represents the processing of different entities, which is the usual process descriptor or process control block.
in a Linux system, this is the TASK_STRUCT structure, defined in the Include\linux\sched.h file.
Each process is assigned a TASK_STRUCT structure that contains all the information about the process, and
can track information about the structure at any time.
This structure is the most important data structure for the Linux kernel rollup, which we'll cover in detail below.
1, process state (will record the process waiting, running, or deadlock)
2, dispatch information (by which dispatch function is dispatched, how to dispatch, etc.)
3, the communication status of the process
4, because to insert the process tree, you must have a pointer to the parent-child sibling, of course, the task_struct type
5, time information, (such as calculating the time of execution for CPU allocation)
6, label (decision change process Attribution)
7, can read and write some file information open
8, process context and kernel context
9, processor context
10. Memory Information
Now let's look at how Linux is defined task_struct:
Open/include/linux/sched.h to find the definition of task_struct
struct Task_struct {
volatile long state;Describes whether the process can be executed, or can be interrupted, and other information
unsigned long flags;Flage is the process number, given when the fork () is called
int sigpending;Whether the process is waiting for a signal to be processed
}
----------------------------------------
mm_segment_t Addr_limit; Process address space
Process address space, which distinguishes between kernel processes and normal processes where memory is stored
0-0XBFFFFFFF for User-thead
0-0XFFFFFFFF for Kernel-thread
----------------------------------------
volatile long need_resched;
A dispatch flag that indicates whether the process needs to be re-dispatched,
If it is not 0, dispatch will occur when returning from the kernel state to the user state
----------------------------------------
int lock_depth;Lock depth
Long Nice; Basic time slices of the process
----------------------------------------
unsigned long policy;
Process scheduling strategy, there are three kinds of
Real-time process: SCHED_FIFO,SCHED_RR
Time-sharing process: Sched_other
----------------------------------------
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.
This value is updated when the run queue is locked.
----------------------------------------
unsigned long cpus_runnable, cpus_allowed;
struct List_head run_list;Pointer to run queue
unsigned long sleep_time;Sleep time of the process
----------------------------------------
struct task_struct next_task, prev_task;
Used to connect all the processes in the system into a two-way circular linked list
Its root is init_task.
----------------------------------------
struct Mm_struct active_mm;
Truct 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 runs
int Exit_code, exit_signal;
int pdeath_signal;Parent process termination is a signal sent to a child process
unsigned long personality;
Linux Can run a IBCS2-compliant program generated by another UNIX operating system
----------------------------------------
int did_exec:1;
The Boolean amount that is designed according to POSIX requirements, the process is executing from
The code inherited from the parent process, or the new program code loaded by Execve
----------------------------------------
pid_t pid; A process identifier that is used to represent a process
pid_t pgrp; Process group identity, which represents the process group to which the process belongs
pid_t tty_old_pgrp;The group ID where the process control terminal resides
pid_t session;Session ID of the process
pid_t Tgid;
int leader;Flag that indicates whether the process is a session leader
----------------------------------------
struct Task_struct p_opptr,p_pptr,p_cptr,p_ysptr,p_osptr;
struct List_head thread_group;Line Threads
struct Task_struct pidhash_next;Used to chain a process into a hash table Pidhash
----------------------------------------
struct Task_struct Pidhash_pprev;
wait_queue_head_t Wait_chldexit;For WAIT4 () use
struct completion vfork_done;For vfork () use
----------------------------------------
unsigned long rt_priority;
Real-time priority, which is used to calculate the weight value of real-time process scheduling.
----------------------------------------
----------------------------------------
IT_REAL_VALUE,IT_REAL_INCR; For real timers, Unit jiffies
The system is based on the It_real_value//setting the first termination time of the timer.
When the timer expires, send the SIGALRM signal to the process, and according to
IT_REAL_INCR Reset End time, IT_PROF_VALUE,IT_PROF_INCR
For the profile timer, the unit is jiffies. When the process is running,
In any state, each tick causes the It_prof_value value to be reduced by one,
When reduced to 0 o'clock, sends a signal sigprof to the process and resets the time according to the IT_PROF_INCR
The It_virt_value,it_virt_value is used for virtual timers in jiffies units.
Each tick causes the It_virt_value value to be reduced by one when the process is running, regardless of state.
When reduced to 0 o'clock, sends a signal SIGVTALRM to the process, resetting the initial value according to IT_VIRT_INCR.
Real timers are updated on a system-by-time basis, regardless of whether the process is running
Virtual Timer is updated only when the process is running, based on the time consumed by the process in the user state
The profile timer, when the process is running, is consumed by the process
Update (whether in user or kernel state)
----------------------------------------
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 that the process consumes,
unsigned long start_time;//the time that the process was created
Long Per_cpu_utime[nr_cpus], Per_cpu_stime[nr_cpus]; Log the user-state time and the kernel-mentality time consumed by the process on each CPU
----------------------------------------
MM fault and swap info:this can arguably be seen as either mm-specific or thread-specific
Memory pages and exchange information:
Min_flt, the number of pages of the Maj_flt cumulative process (Copy on write and anonymous pages) and the number of primary pages (number of page reads from the mapping file or switching device);
Nswap records the number of pages that the process accumulates, that is, the number of pages written to the switching device.
Cmin_flt, Cmaj_flt, Cnswap records the cumulative number of page faults for all descendants of the ancestor process, the number of main pages and the number of pages swapped out. In the parent process
When a terminated child process is reclaimed, the parent process accumulates this information for the child process into those 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 allows swapping out
Process credentials//processes certification Information
Uid,gid is the user identifier and group identifier of the user who is running the process, typically the Uid,gid//euid,egid of the process creator is a valid Uid,gid
Fsuid,fsgid is file system Uid,gid, these two ID numbers are usually equal to valid uid,gid, and they are used when checking access rights to the file system.
Suid,sgid for backup Uid,gid
uid_t Uid,euid,suid,fsuid;
gid_t Gid,egid,sgid,fsgid;
int ngroups; How many user groups the recording process is in
gid_t Groups[ngroups]; Record the group in which the process resides
kernel_cap_t cap_effective, Cap_inheritable, the power of the cap_permitted;//process, respectively, is the effective bit set, the inheritance bit set, the allowed bit set
int keep_capabilities:1;
struct USER_STRUCT user;
Limits
struct Rlimit rlim[rlim_nlimits]; Process-related resource throttling information
unsigned short used_math; Whether to use the FPU
Char comm[16]; Executable file name of the process being run
File system Info//FileSystem information
int Link_count, Total_link_count;
struct tty_struct tty; Null if no TTY process is located in the control terminal, if the control terminal is not required, then the pointer is empty
unsigned int locks; How many file locks is being held
IPC Stuff//interprocess communication information
struct Sem_undo Semundo; All undo actions on the semaphore by the process
struct Sem_queue semsleeping; When the process is suspended because of a semaphore operation, he logs the pending action in that queue
Cpu-specific State of the This task//process CPU status, when switching, to save to the stop process
In Task_struct
struct THREAD_STRUCT thread;
FileSystem Information File System Information
struct FS_STRUCT fs;
Open File information//opening files information
struct files_struct files;
signal handlers//signal processing function
spinlock_t Sigmask_lock; Protects signal and blocked
struct signal_struct sig; Signal processing function,
sigset_t blocked; The signal that the process is currently blocking, with each signal corresponding to one
struct sigpending pending; Whether the process is waiting for a signal to be processed
unsigned long sas_ss_sp;
size_t Sas_ss_size;
Int (notifier) (void Priv);
void Notifier_data;
sigset_t Notifier_mask; THREAD Group Tracking
U32 parent_exec_id;
U32 self_exec_id;
Protection of (de-) allocation:mm, files, FS, TTY
spinlock_t Alloc_lock;
void Journal_info; Journalling FileSystem Info
};
It's complicated, there's wood, and we're picking out what you want to see.
This article is from the "Straw Sunshine" blog, please be sure to keep this source http://helloleex.blog.51cto.com/10728491/1785328
Linux under Task_struct detailed