Read the nuclear diary (3)

xiaoxiao2021-03-06  124

This article comes from: http: //os.silversand.net Author: sunmoon (2001-08-31 15:00:01)

Each process in Linux is defined by the task_struct data structure. Task_struct is our usual PCB. She is the only means of process control is also the most effective means. When we call for (), the system will generate us A task_struct structure. Then from the parent process, inherit some data, insert the new process into the process tree, so understand the structure of Task_struct for our understanding of the task scheduling (in Linux, the task and process is the same The concept) is the key. Before you analyze the definition of task_struct. Let's push it according to our theory. 1, process status, put the record process in waiting, run, or deadlock 2, dispatch information, from which scheduling function Scheduling, how to schedul, etc. 3, the communication status of the process 4, because to insert the process tree, there must be a pointer to the father and son brothers, of course, is Task_struct type 5, time information, such as calculating the time of execution, so that the CPU assignment 6, label, Decide to change the trip attribute 7, you can read some file information 8, process context, and kernel context 9, processor context 10, memory information, because each PCB is like this, only these structures can meet all requirements of a process Open / Include/Linux/Sched.h Find the definition of task_struct Struct Task_struct {/ * these area Hardcoded - Don't touch * / This is some hardware settings to programs transparent. Where State shows if the process can Execute, or interrupt information. FLAGE is the process number, given when calling for (), addr_limit is the location of the core process and the normal process in the memory place different volatile long state; / * -1 unrunnable, 0 runnable,> 0 stopped * / unsigned long flags; / * per process flags, defined below * / int sigpending; mm_segment_t addr_limit; / * thread address space: 0-0xBFFFFFFF for user-thead 0-0xFFFFFFFF for kernel-thread * / struct exec_domain * exec_domain Long need_resched; / * various fields * / count is a priority counter priorrity long counter; long priority; cycles_t avg_slice; / * SMP and runqueue state * / variables defined for the multiprocessor int has_cpu;. int processor; int last_processor; int lock_depth;. / * Lock depth We can context switch in and out of holding a syscall kernel lock ... * / to sort the tree in the process, the definition of father and son, brother pointer struct task_struct * next_task, * prev_task; struct tas74k_struct * next_run , * prev_run; / * task state * / defines the status of the Task run, and the signal struct Linux_binfmt * binfmt; int exit_code, exit_signal; int pdeath_signal; / * the signal Sent when parent dies * / / * Define Process User Number, user group, and process group * / unsigned long personality; int DID_EXEC: 1; PID_T PID; PID_T PGRP; PID_T TTY_OLD_PGRP; PID_T session;

/ * Boolean value for session group leader * / is the header file of the process group INT Leader; / * * Pointers to (Original) Parent Process, Youngest Child, Younger Sibling, * Older Sibling, Respectively. (P-> Father Can BE Replaced with * p-> p_pptr-> pid) * / Parent-child process Some pointer struct task_struct * p_opptr, * p_pptr, * p_cptr, * p_ysptr, * p_osptr; / * pid hash table linkage. * / Some of the dispatch hash table struct task_struct * pidhash_next; struct task_struct ** pidhash_pprev; / * Pointer to task [] array linkage * / struct task_struct ** tarray_ptr;. struct wait_queue * wait_chldexit; / * for wait4 () wait queue * / struct semaphore * vfork_sem ; / * for vFork () * / unsigned long policy, rt_priority; unsigned long ing it_real_value, it_prof_value, it_virt_value; process's nature is not the same because the real-time process is different from the ordinary process's scheduling algorithm, so that the variable is different from the process of some time information of the process UNSigned long it_real_incr, it_prof_incr, it_virt_incr; struct timer_list real_timer; struct tms times; unsigned long start_time; long per_cpu_utime [NR_CPUS], per_cpu_stime [NR_CPUS]; defines the time slice size / * mm fault and swap info: this can arguably be seen as Either mm-specific or thread-specific * / memory information unsigned long min_flt, maj_flt, nswap, cmin_flt, cmaj_flt, cnswap; int swappable: 1; / * process credentials * / uid_t uid, euid, suid, fsuid; gid_t gid, egid, sgid, fsgid; int ngroups; gid_t groups [NGROUPS]; kernel_cap_t cap_effective, cap_inheritable, cap_permitted; struct user_struct * user; the English comments clear / * limits * / struct rlimit rlim [RLIM_NLIMITS]; unsigned short used_math; char comm [16 ]; / * file system info * / int link_count; struct tty_struct * tty; / * NULL if no tty * / / * ipc stuff * / struct sem_undo * semundo; struct sem_queue * semsleeping; / * tss for this task * / struct Thread_struct tss; / * filesystem information * / struct fs_struct * fs; / * open file information * / struct files_struct * files;

转载请注明原文地址:https://www.9cbs.com/read-125807.html

New Post(0)