Before the introduction of the PCB (Process Control block), the first implementation of a ' progress bar ', and then according to the program written to analyze the specific PCB implementation principles. The ' progress bar ' function is able to be displayed in a single line, while the progress bar has a dynamic growth change, to know the ratio in the progress bar, but also need to be able to
Shows you know if the program is executing.
Here are the programs that are written:
650) this.width=650; "title=" 9.png "src=" Http://s3.51cto.com/wyfs02/M00/82/41/wKioL1dPqcnh9AjzAACjLjP-dGE350.png " alt= "Wkiol1dpqcnh9ajzaacjljp-dge350.png"/>
Use ' = ' to dynamically display the progress bar changes, by using "|/-\\" to indicate the state of the program running, if you want to increase the progress bar dynamically, the output buffer is encountered ' \ n ', the system will output the contents of the buffer, but in the program to write the buffer, use the ' \ N ' definitely not, because every time the buffer will output the content, it will not achieve the purpose of dynamic growth, which requires the use of ' \ R ', ' \ R ' and ' \ n ' is not the same, the former is a carriage return, the latter is a newline. Use ' \ R ' to control the output of the buffer and, when appropriate, use Fflush to force the buffer output.
The following is the result of its operation:
650) this.width=650; "title=" 7.png "src=" Http://s5.51cto.com/wyfs02/M02/82/41/wKioL1dPrNXTqAaXAABF_x6jewY936.png " alt= "Wkiol1dprnxtqaaxaabf_x6jewy936.png"/>
650) this.width=650; "title=" 8.png "src=" Http://s2.51cto.com/wyfs02/M00/82/42/wKiom1dPq-bQOg13AAApyPxVSCo821.png " alt= "Wkiom1dpq-bqog13aaapypxvsco821.png"/>
Note: The detailed process of compiling is shown in the previous blog
The process of compiling the program in Vim has been introduced in detail, and the difference between make and makefile is known, but how does the operating system work? What happened to the process? What does the PCB contain?
Operating system is software and hardware management, the operating system for hardware management, the need to pass the driver to execute, the driver is the equivalent of a performer, between the operating system and hardware. Operating system tasks are generally driver management, memory management, process management, file system management and so on.
A process is a running activity of a program with certain independent functions about a data collection. It is the basic unit of the operating system dynamic execution, in the traditional operating system, the process is not only the basic allocation unit, but also the basic execution unit.
The difference between a process and a program: The program is a binary file, and the process is to load the executable file into memory. The process has a binary file and a set of data structures describing its information (Process Control block PCB)
● The PCB (Process Control block) is used to "describe" a process, containing information about the process, the operating system will connect the PCB
The following are ' processes ':
650) this.width=650; "title=" 10.png "src=" http://s4.51cto.com/wyfs02/M02/82/43/wKiom1dPwhGxWS9ZAAAUeeGoQh0692.png "alt=" Wkiom1dpwhgxws9zaaaueegoqh0692.png "/>
Where: A process consists of two parts, a binary file, and a data structure that describes its information.
Pcb-task_struct
Each process in Linux is defined by the TASK_STRUCT data structure. Task_struct is a PCB. When we call fork (), the system generates a TASK_STRUCT structure for us. Then inherit some data from the parent process, and insert the new process into the process tree for process management. Therefore, understanding the structure of task_struct has a great effect on our understanding of task scheduling.
struct task_struct { volatile long state; // Describes whether the process can be executed, or can be interrupted information unsigned long flags; //Flage is a process number , the signal to be processed on the int sigpending; //process is given when the fork () is called mm_segment_t addr_limit; //process address space, distinguish between kernel process and normal process in memory location //0-0xBFFFFFFF for user-thead //0-0xFFFFFFFF for kernel-thread //Dispatch Flag, Indicates whether the process needs to be re-dispatched, or if it is not 0, a dispatch occurs when returning from the kernel state to the user state volatile long need_resched; int lock_depth; //Lock Depth long nice; Basic time slice of //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, cpus_runnable the value 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 the run queue unsigned long sleep_ Sleep time of the time; //process //is used to connect all processes in the system into a two-way circular list, its 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; Format of executable files run by the struct linux_binfmt *binfmt; //process int exit_code, exit_signal; int pdeath_signal; //parent process termination is a signal sent to a child process unsigned long personality; // Linux can run programs that meet the IBCS2 standards generated by other UNIX operating systems int did_exec : 1; The pid_t pid; //process identifier, which is used to represent a process pid_t pgrp; //Process group identity, which represents the process group to which the process belongs pid_t tty_old_pgrp; //Process Control terminal is located in the group identification pid_Session ID of the t session; //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; //is used to chain processes into the 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 weight values for real-time process scheduling            //IT_REAL_VALUE,IT_REAL_INCR for real timers, Unit for jiffies, system according to it_real_value //sets the first stop time of the timer . when the timer expires, sends a 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 a process is running, 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, it is sent to the process The //signal sigprof and resets the time according to the IT_PROF_INCR. //it_virt_value,it_virt_value for virtual timers, Unit is jiffies. When the process is running, each tick causes the It_virt_value value to be reduced by one to 0 o'clock, regardless of the //state, sending a signal to the process SIGVTALRM, according to    //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 consumed by the process unsigned long start_time; //Process creation Time //record the user-state time and kernel-mentality time consumed by the process on each CPU long per_cpu_utime[nr_cpus], per_cpu_stime[nr_cpus]; //memory page faults and exchange information: //min_flt, maj_flt number of pages of the cumulative process (Copy on Write and anonymous pages) and number of main pages (the number of page reads from the mapping file or interchange //device); nswap the number of pages that the process accumulates, that is, the number of pages written to the switching device. The //cmin_flt, cmaj_flt, cnswap recording process is the cumulative number of page faults for all descendant processes of the ancestor, the number of main pages and the number of pages swapped out. //when a parent process recycles a 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 is allowed to swap out //process authentication information //uid,gid is the user identifier and group identifier of the user who is running the process, typically the process creator's uid,gid //euid,egid is a valid Uid,gid //fsuid,fsgid file system Uid,gid, these two ID numbers are usually equal to valid uid,gid, Use them when checking for access to file //systems. //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 process is logged gid_t groups[ ngroups]; //the group where the process is logged 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]; //Resource restriction information related to the process unsigned short used_math; //whether to use fpu char comm[16]; Executable file name of the //process running //File System Information int link_count, total_link_count; The control terminal where the //NULL if no tty process resides, and if no control terminal is required, the pointer is empty struct tty_struct *tty; unsigned int locks; //Inter-process communication information struct sem_undo *semundo; //Process all undo actions on the Semaphore struct sem_queue *semsleeping; //when a process hangs because of a semaphore operation, he logs the pending action in that queue //the CPU state of the process, when switching, to save to the task_struct of the stop process struct thread_ struct thread; / /File System Information struct fs_struct *fs; //Open File Info struct files_struct *files; //Signal Processing function spinlock_t sigmask_ lock; struct signal_struct *sig; //Signal Processing Functions sigset_t blocked; //process current signal to be blocked, each signal corresponds to one bit struct sigpending pending; //signal to be processed on the process      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;};
This article from "Unintentional persistent" blog, reproduced please contact the author!
PCB (Process Control block)--' task_struct '