One, Process Control block (PCB) structure
The Process Control block (PCB) is a specialized data structure that is set up by the system in order to manage processes. It is used by the system to document the external characteristics of the process and to describe the process of its movement. At the same time, the system can use the PCB to control and manage the process, so that the PCB (Process Control block) is the system-aware process is the only sign of the existence.
The PCB of Linux system includes many parameters, each PCB occupies about 1KB more memory space. The structure used to represent the PCB task_struct is briefly described as follows:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 66676869707172737475767778 |
include/linux/sched.h
struct task_struct {
volatile long state;
struct thread_info *thread_info;
atomic_t usage;
unsigned
long flags;
unsigned
long ptrace;
int lock_depth;
int prio, static_prio;
struct list_head run_list;
prio_array_t *array;
unsigned
long sleep_avg;
long interactive_credit;
unsigned
long long timestamp;
int activated;
unsigned
long policy;
cpumask_t cpus_allowed;
unsigned
int time_slice, first_time_slice;
struct list_head tasks;
struct list_head ptrace_children;
struct list_head ptrace_list;
struct mm_struct *mm, *active_mm;
...
struct linux_binfmt *binfmt;
int exit_code, exit_signal;
int pdeath_signal;
...
pid_t pid;
pid_t tgid;
...
struct task_struct *real_parent;
struct task_struct *parent;
struct list_head children;
struct list_head sibling;
struct task_struct *group_leader;
...
struct pid_link pids[PIDTYPE_MAX];
wait_queue_head_t wait_chldexit;
struct completion *vfork_done;
int __user *set_child_tid;
int __user *clear_child_tid;
unsigned
long rt_priority;
unsigned
long it_real_value, it_prof_value, it_virt_value;
unsigned
long it_real_incr, it_prof_incr, it_virt_incr;
struct timer_list real_timer;
unsigned
long utime, stime, cutime, cstime;
unsigned
long nvcsw, nivcsw, cnvcsw, cnivcsw;
u64 start_time;
...
uid_t uid,euid,suid,fsuid;
gid_t gid,egid,sgid,fsgid;
struct group_info *group_info;
kernel_cap_t cap_effective, cap_inheritable, cap_permitted;
int keep_capabilities:1;
struct user_struct *user;
...
struct rlimit rlim[RLIM_NLIMITS];
unsigned
short used_math;
char comm[16];
...
int link_count, total_link_count;
...
struct fs_struct *fs;
...
struct files_struct *files;
...
unsigned
long ptrace_message;
siginfo_t *last_siginfo;
...
};
|
Scheduling data members:1) Vo Latile long state
Represents the current state of a process. When the process runs, it changes state depending on the situation. The process state has a total of task Runn ING (operational State), Task INTERRUPT ible (interruptible wait state), Task Uninterrupt ible (non-interruptible wait state), Task Zomb IE (zombie State), Task ST opped (suspended state) and other 5 kinds. 2) long PR IO rity process priority, the value of Prio rity gives the time slice length (in jiffies) that the process can use each time the CPU is fetched. 3) The value of the unsigned long rt_priority rt_priority gives priority to the real-time process, rt_priority
1000 gives the time slice length (in jiffies) that the process can use each time the CPU is fetched. 4) long counter counter indicates how long the current process can run when the rotation method is dispatched. The value that is assigned priority at the beginning of the process, and every other clock interrupt is decremented by 1, which causes a new round of scheduling to be reduced to 0 o'clock. 5) unsigned long policy represents the process scheduling strategy for the process. The scheduling strategy is: SCH Ed_other 0, non-real-time process, using the priority-based rotation method. SCH Ed_fifo 1, real-time process, with FIFO algorithm.
SCH ED_RR 2, real-time process, with priority-based rotation methodprocess Queue pointers:1) Struc T task_struct* next_task, * prev_task
In Linux all processes (in the form of PCBs) constitute a doubly linked list,
Next_task and Prev_task are forward and backward pointers to the linked list. 2) struct task_struct* p_opptr, * p_pptr
struct Task_struc t* p_cptr, * p_ysptr, * p_osptr
The above are the original parent process, parent process, child process, and new
Hands of the old brothers process. 3) struct task_struct* pidhash_next
struct task_struct** Pidhash_pprev
The front and back pointers used to chain into the hash table of the process. System processes, in addition to linking the two
To the linked list, it is added to the hash table.Process ID:uid_t uid gid_t gid uid and GID are respectively used for the running process
Identity and user group identification. pid_t pid pid_t pgrp pid and PGRP are running processes respectively.
Process identification number and process group identification number time data member: Long Per_cpu_utime [Nr_cpus] Per_cpu_stime
[Nr_cpus]
Per_cpu_utime is the time the user state process is running, per_cpu_
Stime is the time process creation time for the kernel-state process to run unsigned long start_time
File System data members:struct fs_struct* FS
FS maintains the relationship information between the process itself and the VFS (virtual file system).
struct FS_STRUCT
{
Atom ic_t count;
RW lock_t lock;
int umask;
struct dentry* root, * pwd, * altroot;
struct VFSM ount* rootmnt, * pwdmnt, * ALTROOTMNT;
}
where Root, Rootm NT is the root directory of the Dentry and its mount point Vfsmount.
PWD, Pwdmnt is the dentry of the current working directory and the VFS of its mount point.
Mount Altroot, Altrootmnt is the original root target after the save root node is replaced
Dentry and the vfsmount of its mount point.Memory data members:1) struct mm_struct* mm
In Linux, the on-demand paging strategy addresses the memory requirements of the process.
Task_struct data member mm points to Mm_truc T-junction on storage management
Frame. 2) struct mm_struct* active_mm
ACTIVE_MM points to the active address space. 3) Mm_segm ent_t Addr_ Lim it
Represents a thread-space address.
User thread space address: 0..0xBFFFFFFF.
Kernel thread space Address: 0..0XFFFFFFFF4) spinlock_t ALLOC_ Lock
The spin lock used when applying for space. The main function of the spin lock is the critical section
Protection.Page Management:1) int Swappable:1
Whether the page that the process occupies can be swapped out. Swappab Le is 1, which indicates that it can be swapped out.
2) unsigned long min_flt, maj_ Flt
The process accumulates minor number of pages and major pages.
3) unsigned long Nswap
The cumulative number of pages swapped out for this process.
4) unsigned long swap_cnt
The maximum number of pages that can be swapped out in the next loop.
Second, makefile
Makefile defines a set of rules to specify which files need to be compiled first, which files need to be compiled, which files need to be recompiled, and even more complex function operations, and the benefit of makefile is that "automated compilation", once written, requires only a make command, The whole project is completely automatically compiled, which greatly improves the efficiency of software development. Make is a command tool that is a command tool that interprets instructions in makefile.
Makefile to tell the make command how to compile and link the several files. The rules are:
1) If the project has not been compiled, then all of our C files are compiled and linked.
2) If a few C files of this project are modified, then we only compile the modified C file and link the target program.
3) If the header file for this project is changed, then we need to compile the C file referencing the header files and link the target program.
Here is a simple example: (Implementation of the progress bar)
1.vim PROC.C Write (Implementation of the progress bar)
2. Vim Makefile Write
There are no parameters in the first row, just a colon (:) lists the required files in the compilation, and make knows that it needs to be recompiled when it changes in any of the files in the first row .
Among them . Phony means that clean is a "pseudo-target" that clears all. o files,. o files are target files
3, execute make command can compile PROC.C this program
Process Control block (PCB) structure