Analysis of task_struct structure field in Linux __linux

Source: Internet
Author: User
Tags posix


Task_struct: is a data structure of the Linux kernel. It is placed in RAM (running memory) and contains information about the process. Each process puts its own information in the TASK_STRUCT data structure.

The Task_struct field analysis is as follows:

TASK_STRUCT//Process Descriptor

Struct task_struct

{

1. Data member when symmetric multiprocessor mode (SMP) is supported

(1), int processor; CPU the process is using

(2), int last_processor; The last CPU used by the process

(3), int lock_depth; Depth of system kernel lock when context switch

2. Other data members

(1), unsigned short used_math; Whether to use MPU

(2), Char comm[16]; File name of executable file that the process is running

(3), struct rlimit rlim[rlim_nlimits]; Structure Rlimit for resource management, defined in linux/include/linux/resource.h, there are two members: Rlim_cur is the current maximum number of resources; Rlim_max is the maximum number of resources available.

(4), int errno; System call error number for last error, 0 indicates no error. When the system call returns, the full amount also owns the error.

(5), long debugreg[8]; Saves the value of the Intel CPU debug register, which is used in ptrace system calls.

(6) struct Exec_domain *exec_domain; Linux can run programs that meet the IBCS2 standard generated by other Unix operating systems on 80386 platforms. Messages about differences between such programs and Linux programs are saved by the exec_domain structure.

(7) unsigned long personality; Linux can run programs that meet the IBCS2 standard generated by other Unix operating systems on 80386 platforms. Personality further describes the "personality" information on what UNIX platform the Process execution program belongs to. Usually there are per_linux, Per_linux_32bit, Per_linux_em86, PER_SVR3, PER_SCOSVR3, per_wysev386, PER_ISCR4, PER_BSD, Per_xenix and Per_ Mask and so on,

(8) struct LINUX_BINFMT *binfmt; Point to the global execution file format structure to which the process belongs, total A. Out, script, Elf and Java, etc. four kinds. The structure is defined in Include/linux/binfmts.h (Core_dump, Load_shlib (FD), Load_binary, Use_count).

(9) int exit_code,exit_signal; The return code that caused the process to exit Exit_code, causing the wrong signal name exit_signal.

(a) int dumpable:1; Boolean amount that indicates whether memory dump can be performed when an error occurs.

(one) int did_exec:1; A Boolean amount designed by POSIX to distinguish whether a process is executing old program code or executing a new code that is Execve loaded.

(a) int tty_old_pgrp; The process displays the group identity where the terminal is located.

(a) struct tty_struct *tty; Information that points to the display terminal where the process is located. If the process does not need to display a terminal, such as the number No. 0 process, the pointer is empty. The structure is defined in Include/linux/tty.h.

(a) struct wait_queue *wait_chldexit; At the end of the process, or after the system call WAIT4, you sleep on the queue to wait for the end of the child process. The structure is defined in include/linux/wait.h.

3, scheduling data members
(1) volatile long states; Represents the current state of a process:
? Task_running: A process that is running or is ready to run in the ready queue run-queue and actually participates in process scheduling.
? Task_interruptible: A process in a waiting queue that wakes up when the resource is valid, or by another process after a signal (signal) or a timed break, to enter the ready queue run-queue.
? Task_uninterruptible: A process in a waiting queue that wakes up when the resource is valid, and cannot be awakened by a signal (signal) or a timed interrupt by another process.
? Task_zombie: A State (zombie state) that represents the end of a process but has not yet perished. At this point, the process has finished running and released most of the resources, but the process control block has not been released.
? Task_stopped: The process is paused and can be awakened by a signal from another process. The reason for this state is two, or the response to receiving Sigstop, SIGSTP, sigttin, or Sigttou signals, or the control of Ptrace system calls from other processes, temporarily handing the CPU over to the control process.
? Task_swapping: The process in which the process page is swapped out of memory.
(2) unsigned long flags; Process Flags:
? Pf_alignwarn Print the Alignment warning message.
? pf_ptraced is monitored by ptrace system calls.
? PF_TRACESYS is tracking.
? The pf_forknoexec process has just been created, but has not yet been executed.
? Pf_superpriv Super User privileges.
? Pf_dumpcore dumped core.
? The pf_signaled process is killed by a signal (signal).
? The pf_starting process is being created.
? The pf_exiting process begins to close.
? PF_USEDFPU the process uses the FPU (SMP only).
? Pf_dtrace delayed trace (used on m68k).
(3) long priority; Process priority. The priority value gives the time that the process can be used each time it acquires the CPU (by jiffies). The priority can be changed by system call Sys_setpriorty (in KERNEL/SYS.C).
(4) unsigned long rt_priority; Rt_priority gives priority to the real-time process, rt_priority+1000 gives the time that the process can be used each time it acquires the CPU (also by jiffies).
(5) long counter; The rotation method is used to indicate how long the process is currently running. At the beginning of the process is the value assigned to the priority, every other tick (clock interruption) of 1, reduced to 0 o'clock caused a new round of scheduling. Rescheduling picks up the counter-value-ready process from the Run_queue queue and gives the CPU the right to use it, so counter plays the role of dynamic priority of the process (priority is static priority).
(6) unsigned long policy; The process scheduling policy for the process, which can be changed (see KERNEL/SCHED.C) through the system call Sys_sched_setscheduler (). Scheduling strategies are:

? Sched_other 0 non-real-time processes, based on the priority of the rotation method (round robin).
? Sched_fifo 1 Real-time process, with advanced first out algorithm.
? SCHED_RR 2 Real-time process, using the rotation method based on priority.
4,   signal processing
(1) unsigned a signal received by a long signal; //process. Each digit represents a signal, a total of 32 kinds. Position is valid. The
(2) unsigned the bit mask that a long blocked;  //process can accept signals. The position indicates a mask, and the reset means no masking.
(3) struct signal_struct *sig;  //because signal and blocked are all 32-bit variables, Linux can accept up to 32 signals. For each signal, the process can be selected by the PCB's SIG attribute using a custom handler function, or the system's default handler function. The structure of assigning various information processing functions is defined in include/linux/sched.h.
5, Process queue pointers
(1) struct task_struct *next_task,*prev_task; //all processes (in the form of a PCB) to form a two-way list. Next_task and is the back and forth pointer of the linked list. The head and tail of the linked list are init_task (ie, process No. 0). The
(2) struct task_struct *next_run,*prev_run;  //A two-way cyclic list of processes that are running or can run that have task_running process status, that is, run _queue ready queue. The forward and backward pointers of the linked list are used in Next_run and Prev_run, and the head and tail of the linked list are init_task (ie, No. 0 process).
(3) struct task_struct *p_opptr,*p_pptr; struct task_struct *p_cptr,*p_ysptr,*p_osptr;  // These are pointers to the original parent process (original parent), the parent process (parent), the subprocess (youngest child), and the new and old sibling process (younger Sibling,older sibling).

The

Process identity
(1) unsigned short uid,gid;  //uid and GID are the user identities and user group identities that run the process.
(2) int groups[ngroups];  //As with most modern UNIX operating systems, Linux allows a process to have a set of user group numbers at the same time. These group numbers can be used for legality checking when a process accesses a file.
(3) unsigned short euid,egid; //euid and Egid are also known as valid UID and GID. For the sake of system security, it is necessary to check the legality of Euid and Egid when running the program. Typically, the UID equals Euid,gid equals Egid. Sometimes, the system gives the average user a temporary root uid and GID (as Euid and egid of the user process) for easy operation. The
(4) unsigned short fsuid,fsgid;  //fsuid and fsgid are known as file System UID and GID, and are used for legitimate checks of file system operations and are unique to Linux identification types. They are generally consistent with euid and Egid, but in NFS file Systems Server for NFS needs to access files as a special process, modifying only the Fsuid and Fsgid of the client process. The
(5) unsigned short suid,sgid;  //suid and sgid are introduced according to the POSIX standard, which preserves the true UID and GID when system calls change the UID and GID.
(6) int pid,pgrp,session;  //process identification number, process organization number and session identification number, related system calls (see program KERNEL/SYS.C) have Sys_setpgid, Sys_ Getpgid, Sys_setpgrp, Sys_getpgrp, Sys_getsid and Sys_setsid.
(7) int leader;
whether the session is the supervisor, the Boolean amount.
7,   time data member
(1) unsigned long timeout;  //

Related Article

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.