" Process Control block
In Linux, process information is stored in the data structure called the Process control block, each process has a Process Control block (PCB) in the kernel to maintain process-related information, and the process control block of the Linux kernel is the TASK_STRUCT structure. In Linux, this structure is called task_struct.
Task_struct is a data structure of the Linux kernel that is loaded into RAM and contains information about the process.
Each process puts its information in the TASK_STRUCT data structure?, Task_struct contains the content:
》》》》》》
Mark: Describes the process of the only mark,? to distinguish other processes.
Status: Task status, exit code, exit signal, etc.
Priority: The priority relative to other processes.
Program counter: The address of the next instruction that is about to be taken in the program.
Memory pointers: Pointers to program code and process-related data, as well as memory blocks shared with other processes
Data: The data in the register of the processor when the process is in progress.
I/O status information: includes the explicit I/O request, the I/O device assigned to the process, and the list of components that were made by the process.
Accounting information: May include the sum of processor time, the sum of the number of clocks, time limit, accounting number, etc.
》》》》》》》
The data structure that holds the process information is called task_struct and can be found in include/linux/sched.h.
All the shipping? In the system?
The information stored in the task_struct is very much, the following is the entire structure of the content, you can learn to understand:
The TASK_STRUCT structure in Linux is as follows:
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, which distinguishes between kernel processes and normal processes in memory locations//0-0xbffffffffor User-thead//0-0XFFFFFFFF for Kernel-thread
A dispatch flag that indicates whether the process needs to be re-dispatched, or not 0, when it is returned from the kernel state to the user state, a dispatch occurs
volatile long need_resched;
int lock_depth; Lock depth
Long Nice; Basic time slices of the process
Process scheduling strategy, there are three kinds, real-time process: SCHED_FIFO,SCHED_RR, timeshare 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 1 This value is updated when the running queue is locked
unsigned long cpus_runnable, cpus_allowed;
struct List_head run_list; //Pointer to run queue
unsigned long sleep_time; //Process sleep time
Used to connect all processes in the system into a two-way circular linked list whose root 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 runs
int Exit_code, exit_signal;
int pdeath_signal;//The signal sent to the child process when the parent process terminates
unsigned long personality;
Linux can run programs that meet IBCS2 standards generated by other UNIX operating systems
int did_exec:1;
pid_t pid;//Process identifier, which is used to represent a process
pid_t pgrp;//Process group ID, 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; 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
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, using it to calculate the weight value of real-time process scheduling
IT_REAL_VALUE,IT_REAL_INCR for real timers, unit jiffies, system based on It_real_value
Sets the first stop time of the timer. When the timer expires, send the SIGALRM signal to the process, and according to
IT_REAL_INCR Reset termination time, IT_PROF_VALUE,IT_PROF_INCR for the profile timer, Unit jiffies.
When the process runs, each tick causes the It_prof_value value to be reduced by one at any state, and when it is reduced to 0 o'clock, the process is sent
The signal sigprof 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. When the process is running, no matter what
State, each tick causes the It_virt_value value to be reduced by one to 0 o'clock, sending a signal to the process sigvtalrm, depending on
IT_VIRT_INCR resets the initial value.
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; Time the process was created
Log the user-state time and the kernel-mentality time consumed by the process on each CPU
Long Per_cpu_utime[nr_cpus], Per_cpu_stime[nr_cpus];
Memory pages and exchange information:
Min_flt, Maj_flt number of secondary pages of the cumulative process (Copy on write and anonymous pages) and the number of main page pages (from the mapping file or interchange
The number of pages that the device reads); 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.
When the parent process recycles the terminated child process, 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 authentication Information
Uid,gid is the user identifier and group identifier of the user running the process, usually the uid,gid of the process creator
Euid,egid for effective Uid,gid
Fsuid,fsgid for file system Uid,gid, these two ID numbers are usually equal to valid uid,gid, check for file
Use them when accessing the 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
The power of the process, respectively, is the set of valid bits, the set of inherited bits, the allowed bit set
kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
int keep_capabilities:1;
struct User_struct *user;
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
int Link_count, TOTAL_LINK_ count; File System Information
Null if no TTY process is located in the control terminal, if the control terminal is not required, then the pointer is empty
struct Tty_struct *tty;
unsigned int locks;
Inter-process 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 state of the process, when switching, to be saved to the task_struct of the stop process
struct THREAD_STRUCT thread;
struct Fs_struct *fs; File System Information
struct Files_struct *files; Open File Information
spinlock_t Sigmask_lock; Signal processing functions
struct Signal_struct *sig; Signal processing functions
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;
U32 parent_exec_id;
U32 self_exec_id;
spinlock_t Alloc_lock;
void *journal_info;
};
TASK_STRUCT structure of the Process control block