Chinese introduction of task_struct in Linux kernel (2.4 kernel)

Source: Internet
Author: User

 

Source:
Chinaunix blog Date:
(0 comments in total) I want to comment
 

1. scheduling data member
(1) Volatile long states;
Indicates the current status of the process:
? Task_running: A running process or a running process in the ready queue run-queue. The process is actually scheduled.
? Task_interruptible: a process in the waiting queue that wakes up when the resource is valid. It can also be triggered by other processes through the signal (signal) or timed interruption to enter the ready queue run-queue.
? Task_uninterruptible: a process in the waiting queue. It is awakened when the resource is valid. It cannot be awakened by other processes through signal or timed interruption.
? Task_zombie: A State that indicates the process has ended but has not died ). At this point, the process has ended and most resources have been released, but the process control block has not been released.
? Task_stopped: the process is paused and can be awakened only by signals from other processes. There are two reasons for this status: Response to the signal sigstop, sigstp, sigttin or sigttou, or control by the ptrace System Call of other processes, temporarily handing over the CPU to the control process.
? Task_swapping: process in which the process page is swapped out of memory.
(2) unsigned long flags;
Process flag:
? Pf_alignwarn prints the alignwarn warning.
? Pf_ptraced is monitored by the ptrace system call.
? Pf_tracesys is tracking.
? The pf_forknoexec process has just been created but has not been executed yet.
? Pf_superpriv Super User Privilege.
? Pf_dumpcore dumped core.
? The pf_signaled process is killed by the signal (signal.
? The pf_starting process is being created.
? The pf_exiting process is disabled.
? Pf_usedfpu this process uses FPU (SMP only ).
? Pf_dtrace delayed trace (used on m68k ).
(3) Long priority;
Process Priority. The value of priority indicates the time (in jiffies) that a process can use after obtaining the CPU ). The priority can be changed by calling sys_setpriorty (in kernel/sys. C ).
(4) unsigned long rt_priority;
Rt_priority indicates the priority of the real-time process. rt_priority + 1000 indicates the time that the process can use after obtaining the CPU (also based on jiffies ). Real-time
The priority of a process can be changed by calling sys_sched_setscheduler () (see kernel/sched. C ).
(5) Long counter;
During rotation scheduling, it indicates how long the process can run. When the process starts running, it is assigned a value of priority, and the number of tick (clock interruption) decreases by 1 every other time. When it is reduced to 0, a new round of calls will be triggered.
Degree. Rescheduling selects the ready process with the highest counter value from the run_queue queue and gives the CPU permission. Therefore, counter plays a role in the dynamic priority of the process.
(Priority is the static priority ).
(6) unsigned long policy;
The process scheduling policy of this process can be changed by calling sys_sched_setscheduler () (see kernel/sched. C ). Scheduling policies include:
? Sched_other 0 is a non-real-time process. It is based on the round robin (Round Robin) method ).
? Sched_fifo 1 Real-time process, with the first-in-first-out algorithm.
? Sched_rr 2 Real-time process, with priority-based rotation method.
2. Signal Processing
(1) unsigned long signal;
The signal received by the process. Each represents a signal of 32 types. The specified location is valid.
(2) unsigned long blocked;
The bitmask that the process can accept. The position indicates blocking, And the reset indicates not blocking.
(3) struct signal_struct * SIG;
Because both signal and blocked are 32-bit variables, Linux can only accept up to 32 signals. For each signal, each process can select a custom position from the SIG attribute of the PCB.
Or the system's default processing function. The structure of various information processing functions is defined in include/Linux/sched. h. The signal check is scheduled after the system call is completed,
And after the "slow" interrupt service program ends (IRQ # _ interrupt (), see 9. Section 5 "Start the kernel ").
3. Process queue pointer
(1) struct task_struct * next_task, * prev_task;
All processes (in the form of PCB) form a two-way linked list. Next_task and are the front and back pointers of the linked list. Both the head and end of the linked list are init_task (process 0 ).
(2) struct task_struct * next_run, * prev_run;
A two-way cyclic linked list consisting of running or runable processes whose process statuses are task_running, that is, run_queue ready queue. The forward and backward pointers of the linked list use next_run and prev_run. The head and tail of the linked list are init_task (process 0 ).
(3) struct task_struct * p_opptr, * p_pptr; and struct task_struct * p_cptr, * p_ysptr, * p_osptr;
The above are pointers to the original parent process (original parent), parent process (parent), child process (youngest child), and new and old brother processes (younger sibling, older sibling.

4. process ID
(1) unsigned short uid, Gid;
UID and GID are the user ID and user group ID of the running process.
(2) int groups [ngroups];
Like most modern Unix operating systems, Linux allows processes to have a group of user group numbers at the same time. When a process accesses a file, these group numbers can be used for validity checks.
(3) unsigned short EUID, EGID;
EUID and EGID are also called valid UID and GID. For the sake of system security permissions, check the validity of EUID and EGID when running the program. Generally, uid is equal to EUID,
GID is equal to EGID. Sometimes, the system will grant the general user temporary root UID and GID (as the EUID and EGID of the user process) for easy operation.
(4) unsigned short fsuid, fsgid;
Fsuid and fsgid are called the UID and gid of the file system. They are used to check the validity of file system operations and are unique identification types in Linux. They are generally the same as EUID and EGID respectively.
Consistency, but in the NFS file system, the NFS server must be used as a special process to access the file. In this case, only the fsuid and fsgid of the customer process are modified.
(5) unsigned short SUID, SGID;
SUID and SGID are introduced according to POSIX standards. They are used to retain the real UID and GID when the system call changes UID and GID.
(6) int PID, pgrp, session;
Process ID, process organization ID, and session ID. system calls (see program kernel/sys. c) Include sys_setpgid, sys_getpgid, sys_setpgrp, sys_getpgrp, sys_getsid, and sys_setsid.
(7) int leader;
Whether it is the session supervisor or a Boolean value.
5. Time data member
(1) unsigned long timeout;
It is used for Software Timing to indicate how long the process interval has been awakened again. Tick is used.
(2) unsigned long it_real_value, it_real_iner;
Used for itimer (Interval
Timer) Software Timing. Jiffies is used as the unit, and each tick reduces it_real_value to 0 to send signal sigalrm to the process, and reset the initial value. Initial Value
Save it_real_incr. For specific code, see the it_real_fn () function in kernel/itimer. C ().
(3) struct timer_list real_timer;
A timer structure (two timer structures are available in Linux, and the other is called old_timer ). The data structure is defined in include/Linux/Timer. H. For the relevant operation functions, see add_timer () and del_timer () in kernel/sched. C.
(4) unsigned long it_1__value, it_1__incr;
Itimer Software Timing of process user State execution time. Jiffies is used. When a process is running in user mode, each tick reduces it_assist_value by 1 to 0.
Sends a signal to the process, and resets the initial value. The initial values are saved by it_virt_incr. For specific code, see the functions in kernel/sched. C.
Do_it_virt ().
(5) unsigned long it_prof_value, it_prof_incr;
It is also the timing of the itimer software. Jiffies is used. No matter whether the process is running in the user or kernel state, each tick will reduce it_prof_value by 1 to 0.
Send sigprof and reset the initial value. The initial values are saved by it_prof_incr. For specific code, see the do_it_prof function in kernel/sched. C.
(6) Long utime, stime, cutime, cstime, start_time;
The preceding steps show the running time of processes in the user State, the running time of processes in the kernel state, the total running time of all levels of sub-processes in the user State, and the running of all levels of sub-processes in the core state. total time, and the time when the process was created.
6. semaphore data member
(1) struct sem_undo * semundo;
The process generates an Undo operation for each operation of the semaphore, which is described by the sem_undo structure. The linked list composed of the Undo operations of the same process is composed
Semundo attribute indication. When a process stops abnormally, the system calls the Undo operation. The sem_undo member semadj points to a data array, indicating the number of Undo tasks. Structure
Defined in include/Linux/SEM. h.
(2) struct sem_queue * semsleeping;
Each set of semaphores corresponds to a sem_queue waiting queue (see include/Linux/SEM. h ). When a process is blocked by operating on the semaphore set, it is mounted
Semsleeping indicates the sem_queue queue of the semaphore set. In turn, semsleeping. Sleeper points to the PCB of the process.
7. process context
(1) struct desc_struct * LDT;
The pointer of the process's Local Descriptor Table for CPU-Segment Storage Management, used to simulate wine Windows programs. In other cases, if the value is null, the LDT of the process is the arch ult_ldt defined by arch/i386/traps. C.
(2) struct thread_struct TSS;
Task status segment, whose content corresponds to Intel cpu tss, such as various General registers. during CPU scheduling, the TSS of the currently running process is saved to the TSS of the PCB, And the TSS of the newly selected process is copied to the TSS of the CPU. The structure is defined in include/Linux/tasks. h.
(3) unsigned long saved_kernel_stack;
Stack pointer saved for the simulation program of the MS-DOS (or called the system call vm86.
(4) unsigned long kernel_stack_page;
During kernel-state running, each process has a kernel stack, and its base address is stored in kernel_stack_page.
8. File System Data Member
(1) struct fs_struct * FS;
FS stores the relationship message between the process itself and VFS, where Root points to the root directory node, PWD points to the current directory node, umask provides the access mode for new files (which can be called by the System)
Umask change). Count is a reserved attribute in Linux, as shown in the following figure. The structure is defined in include/Linux/sched. h.
(2) struct files_struct * files;
Files contains the files currently opened by the process (struct file * FD [nr_open]). In Linux, a process can open up to nr_open files at the same time. In addition, the first three items are pre-configured as standard input, standard output, and error message output files.
(3) int link_count;
The number of links.
9. Memory Data Member
(1) struct mm_struct * mm;
In Linux, The on-demand paging policy is used to address the memory requirements of processes. The data member mm of task_struct points to the mm_struct structure about storage management. This includes
Virtual Memory queue MMAP, pointing to the virtual memory block described by several vm_area_struct. To speed up access, mmap_avl in mm maintains an AVL Tree. In the tree
All vm_area_struct virtual memory blocks point from the left pointer to the adjacent low virtual memory block, and the right pointer to the adjacent high virtual memory block.
The structure is defined in include/Linux/sched. h.
10. Page Management
(1) int swappable: 1;
Whether the Memory Page occupied by the process can be swapped out. If the value of swappable is 1, it indicates that swappable can be swapped out. The reset and placement of this flag are all executed in the do_fork () function (see kerenl/fork. C ).
(2) unsigned long swap_address;
The process page with a VM address lower than swap_address has previously been swapped out or has been swapped out. The next page that can be swapped out by a process starts with swap_address. See swap_out_process () and swap_out_pmd () (see mm/vmscan. C ).
(3) unsigned long min_flt, maj_flt;
The total number of minor missing pages and the number of major missing pages of the process. Maj_flt is basically the same as min_flt, but the Count range is wider than that of the latter (see fs/buffer. C and
Mm/page_alloc.c ). Min_flt is added only in do_no_page () and do_wp_page () (see mm/memory. C ).
Write operation page.
(4) unsigned long nswap;
The total number of pages exchanged by this process.
(5) unsigned long cmin_flt, cmaj_flt, cnswap;
The total number of child processes at all levels of this process as the ancestor is counted in and out pages.
(6) unsigned long old_maj_flt, dec_flt;
(7) unsigned long swap_cnt;
The maximum number of pages that can be exchanged for the next signal.
11. Support for data members in symmetric multi-processor (SMP) Mode
(1) int processor;
CPU used by the process.
(2) int last_processor;
The CPU used by the process for the last time.
(3) int lock_depth;
The depth of the system kernel lock during context switching.
12. Other data members
(1) unsigned short used_math;
Whether to use FPU.
(2) Char comm [16];
The name of the executable file that the process is running.
(3) struct rlimit rlim [rlim_nlimits];
The structure rlimit is used for resource management. It is defined in Linux/include/Linux/resource. H. There are two members: rlim_cur is the most current resource
A large number; rlim_max is the maximum number of resources available. In the i386 environment, the controlled resources have a total of rlim_nlimits items, that is, 10 items, which are defined in
In Linux/include/ASM/resource. H, see the following table:
(4) int errno;
The system call error code for the last error. 0 indicates no error. This error number is also available for the full process returned by the system call.
(5) Long debugreg [8];
Saves the Intel CPU debugging register value, which is used in ptrace system calls.
(6) struct exec_domain * exec_domain;
Linux can run programs that comply with the ibcs2 standard generated by other UNIX operating systems on the 80386 platform. Messages about the differences between such programs and Linux programs are saved in the exec_domain structure.
(7) unsigned long personality;
Linux can run programs that comply with the ibcs2 standard generated by other UNIX operating systems on the 80386 platform.
Personality further describes the UNIX platform's "personality" information of the program being executed by the process. Per_linux, per_linux_32bit,
Per_linux_em86, per_svr3, per_scosvr3, per_wysev386, per_iscr4, per_bsd,
Per_xenix and per_mask. For details, see include/Linux/personality. h.
(8) struct linux_binfmt * binfmt;
Point to the global execution File Format Structure of the process, a in total. Out, script, elf, and Java. The structure is defined in include/Linux/binfmts. H (core_dump, load_shlib (FD), load_binary, and use_count ).
(9) int exit_code, exit_signal;
The return code exit_code that causes the process to exit, causing the wrong signal name exit_signal.
(10) int dumpable: 1;
Boolean, indicating whether memory dump can be performed when an error occurs.
(11) int did_exec: 1;
The POSIX-based Boolean design distinguishes whether the process is executing the old program code or executing the new Code loaded by execve.
(12) int tty_old_pgrp;
The process displays the group ID of the terminal.
(13) struct tty_struct * tty;
Point to the display terminal where the process is located. If the process does not need to display terminals, such as process 0, the pointer is null. The structure is defined in include/Linux/tty. h.
(14) struct wait_queue * wait_chldexit;
After the process ends or wait4 is called by the system, you can sleep yourself (parent process) in the queue to wait for the child process to end. The structure is defined in include/Linux/Wait. H.
13. global variables of the Process queue
(1) Current;
The pointer to the currently running process. In SMP, it points to the current process of the CPU being scheduled in the CPU group:
# Define current (0 + current_set [smp_processor_id ()])/* sched. H */
Struct task_struct * current_set [nr_cpus];
(2) struct task_struct init_task;
That is, the PCB of process 0 is the "root" of the process, and the initial value is always init_task.
(3) struct task_struct * task [nr_tasks];
Process queue array, which specifies the maximum number of processes that the system can run simultaneously (see kernel/sched. C ). Nr_tasks is defined in include/Linux/tasks. h
The value is 512. Each process occupies an array element (the subscript of the element is not necessarily the PID of the process). task [0] must point to init_task (process 0 ). You can use
The task [] array traverses the PCB of all processes. However, Linux also provides a macro definition for_each_task () (see
Include/Linux/sched. h), which traverses the PCB of all processes through next_task:
# Define for_each_task (P )/
For (P = & init_task; (P = p-> next_task )! = & Init_task ;)
(4) unsigned long volatile jiffies;
Linux benchmark time (see kernal/sched. C ). When the system is initialized, the value 0 is cleared. After that, the clock interruption service program do_timer () increases by 1 every 10 ms.
(5) int need_resched;
Reschedule flag bit (see kernal/sched. C ). When Linux scheduling is required. Determine whether the flag is set before the system call returns (or in other cases. Call schedule immediately for CPU scheduling.
(6) unsigned long intr_count;
Record the number of nested layers of the interrupt service program (see kernal/softirq. C ). During normal operation, the intr_count value is 0. When processing hardware interruptions, executing tasks in the task queue, or executing tasks in the bottom half queue, intr_count is not 0. In this case, the kernel prohibits some operations, such as rescheduling.

This article is from the chinaunix blog. If you want to view the original text, click:Http://blog.chinaunix.net/u/16490/showart_470150.html

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.