My OS review-process (UP)

Source: Internet
Author: User
Tags bit set session id semaphore volatile

The previous post reviewed the general overview of the operating system-my operating system review-an overview of the operating system, including the definition of the operating system, its evolution, and the structure of the operating system. Next we begin to review the computer knowledge in detail, including process, processor, memory and so on. This article first review the process and its important concept, which is the previous part of the process series.

One, what is concurrency

What is concurrency? Quite simply, the multi-channel batch system described earlier is typical of concurrent execution. Here again over the high-performance multi-channel batch processing system, its essence is to maintain the system resources, the CPU runs a task, if the task is interrupted, such as the need for IO request, then the CPU directly to run other tasks, the original task IO request by the IO device itself processing. There is a well-known figure--representing concurrency:

  

, assuming that the computer has input, calculation, output of the three parts, a set of tasks to execute, and concurrency is the same as the assembly line parts. At some point, only one program occupies the CPU (the computing device). So what is parallel? Parallel is built on multi-core, that is, multiple CPUs running simultaneously, then there are several CPUs, at the same time there are several programs running simultaneously. So the computer has only one CPU of the bitter force programmer can only concurrent.

The actual concurrency of modern systems is much more complex, and the concurrency of modern computer systems is based on time slices, that is, in a very short time, each process is run separately. In this way, each process is running continuously on a macro level, and virtually every process runs intermittently. So the question is, what is the process?

 

Ii. What is a process

The purpose of the process is to control the concurrent execution of the program. Process entity consists of three parts: program segment, data segment and PCB. We know that the essence of computer operation is the processing machine of data.

-Data segment is a variety of data

--Program section is a series of instructions to operate the computer, that is, the method of manipulating data strategy

The--PCB is the process control block, which controls the timing of running the program segment.

This is how the process is defined in the book: "The process is the processentity running process, is the system for resource allocation and scheduling of an independent unit."

Let's figure out what the process is. a process is a process in which the process entity runs. that is, the process entity does not run, and that is not called a process. A process entity that is not called, not called a process. So, the process has dynamic characteristics . As mentioned above, the purpose of the process is to control the concurrent execution of the program. In order to run multiple programs within a single time slice, the process is introduced. So, the process has concurrency characteristics. a process entity is a basic unit that has independent resources (program segments and data segments), (because PCBs) can independently accept schedules and operate independently. So, the process has its own characteristics . Process running process, because of the many resources involved, the operating environment is not necessarily, but also by other processes, so the operation of the process is not specific predictable. So books are defined, and processes move forward at their own, unpredictable speed. So, the process has asynchronous characteristics. As mentioned above, the process is a process entity and this data structure is called to run. So, the process has structural characteristics.

It can be said that the real understanding of the process of these five characteristics, only to understand the concept of the process. Master with us these rookie of the biggest difference, not lies in the understanding of the system?

iii. Status of the process

There are 3 basic states of a process:

(1) Ready status

At this point the process has the full process entity, as long as the CPU is obtained, that is, as long as the call can be executed immediately, this state is called the ready state. Processes in this state are placed in the ready queue to accept CPU calls at any time.

(2) Execution status

At this point the process has gained CPU and is executing.

(3) Blocking status

A paused state that executes in a process that, for some reason (IO request) cannot continue, becomes ready when the pause is completed.

  In addition to the 3 basic states above, some systems add an additional state.

(4) Suspend status

Why do I need to suspend state? Because sometimes you want some of the executing threads to pause, and after a while, let it go back to the previous state.

A suspended state is a state of stillness, which is equivalent to taking a process out of the execution pipeline and then putting it in to continue execution when needed. Let's take a look at the first three basic states, ready-to-do blocking, blocking is complete and back to ready. Because of the asynchronous nature of the thread, the blocking will end in an indeterminate finite time period. That is, three basic states are dynamic, and there is usually no one thread that is always in a certain state. The suspended state is static relative to them, because it is controlled and is a distraction to threads that advance at unpredictable speeds.

  In addition, there are usually two more common states for management needs.

(5) Create status

We know that process entities include program segments, data segments, and PCBs. The creation state refers to the fact that the PCB has been created, for some reason (the program segment or data segment is not in memory, etc.), and the process has not been put into the ready queue in this state.

(6) Termination status

The termination of a thread is also a process. The terminating state refers to the state in which the thread is recycled except for the system resources outside the PCB. At this point the thread really terminates.

Iv. Core PCB of the process(1) What is a PCB?

As part of the process entity, the PCB is a data structure used to control the running of the process. It contains the status of the process, priority, the state of operation, processor status, memory address of the program data and other information, once the operating system is called, the operating system from the PCB to obtain information, to restore the process before blocking the site, continue to execute.

(2) information contained in the PCB

1) process identifier . Used to identify a unique process. Includes an internal identifier that facilitates system invocation and an external identifier that facilitates user invocation. Process identifiers typically also include information such as the parent, child processes, and the owning user.

2) processor status information .

The processor state information refers to the environment information when the processor calls the thread. When the processor processes the calling process, much of the information in the process is placed in the registers of the processing machine. When a process is blocked or suspended, the running information in the register is saved to the PCB so that the next time the process is called back to the running site.

3) process scheduling information .

Process scheduling information refers to the necessary information required for the scheduling of this process. Includes the status of this process (6), process priority, process wait time, process execution time (which may be prioritized), blocking reason, parent-child process relationship, and so on.

4) Process Control information .

Process Control information refers to the process's resource information and the required information when the process is switched, including the memory address of the process's program and data, the mechanism of process synchronization and communication, a list of process resources, a pointer to the next process PCB (if the PCB is organized by link), etc.

(3) Specific information about the PCB (structure)

Here we look at the specific structure of the PCB in Unix, in order to have a clear understanding of the PCB. This thing is actually just one thing:

(The following code was excerpted from http://blog.sina.com.cn/s/blog_65403f9b0100gs3a.html)

structtask_struct {volatile LongState//describes whether the process can be executed, or can be interrupted, and other informationUnsignedLongFlags//Flage is the process number, given when the fork () is calledintsigpending;//whether the process is waiting for a signal to be processedmm_segment_t Addr_limit;//process address space, which distinguishes between kernel processes and normal processes where memory is stored//0-0xbfffffff for User-thead//0-0xffffffff for Kernel-thread//A dispatch flag that indicates whether the process needs to be re-dispatched, or not 0, when it is returned from the kernel state to the user state, a dispatch occursvolatile Longneed_resched;intlock_depth;//Lock DepthLongNice//basic time slices of the process//process scheduling strategy, there are three kinds, real-time process: SCHED_FIFO,SCHED_RR, Timeshare process: Sched_otherUnsignedLongpolicy;structMm_struct *mm;//Process Memory Management informationintprocessor;//If the process is not running on any CPU, the value of cpus_runnable is 0, otherwise 1 This value is updated when the running queue is lockedUnsignedLongcpus_runnable, cpus_allowed;structList_head run_list;//pointer to run queueUnsignedLongSleep_time;//sleep time of the process//used to connect all processes in the system into a two-way circular linked list whose root is Init_taskstructTask_struct *next_task, *Prev_task;structMm_struct *active_mm;structList_head local_pages;//point to Local pageUnsignedintAllocation_order, nr_local_pages;structLINUX_BINFMT *binfmt;//The format of the executable file that the process runsintExit_code, exit_signal;intpdeath_signal;//parent process termination is a signal sent to a child processUnsignedLongpersonality;//Linux can run programs that meet IBCS2 standards generated by other UNIX operating systemsintDid_exec:1; pid_t pid; //a process identifier that is used to represent a processpid_t pgrp;//Process group identity, which represents the process group to which the process belongspid_t tty_old_pgrp;//the group ID where the Process Control terminal residespid_t session;//session ID of the processpid_t Tgid;intLeader//Indicates whether the process is a session leaderstructTask_struct *p_opptr,*p_pptr,*p_cptr,*p_ysptr,*p_osptr;structList_head Thread_group;//Line ThreadsstructTask_struct *pidhash_next;//used to chain a process into a hash tablestructTask_struct * *pidhash_pprev;wait_queue_head_t Wait_chldexit; //for WAIT4 () usestructCompletion *vfork_done;//for Vfork () useUnsignedLongrt_priority;//real-time priority, which calculates the weight value for real-time process scheduling//IT_REAL_VALUE,IT_REAL_INCR for real timers, unit jiffies, system based on It_real_value//sets the first stop time of the timer. When the timer expires, send the 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 the process runs, 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, the process is sent//the signal sigprof and resets the time according to the IT_PROF_INCR.//The It_virt_value,it_virt_value is used for virtual timers in jiffies units. When the process is running, no matter what//state, each tick causes the It_virt_value value to be reduced by one to 0 o'clock, sending a signal to the process sigvtalrm, depending on//IT_VIRT_INCR resets the initial value. UnsignedLongIt_real_value, It_prof_value, it_virt_value;unsignedLongit_real_incr, IT_PROF_INCR, It_virt_value;structTimer_list Real_timer;//pointer to real-time timerstructTMS Times;//record the time that the process consumesUnsignedLongStart_time;//time the process was created//Log the user-state time and the kernel-mentality time consumed by the process on each CPULongPer_cpu_utime[nr_cpus], Per_cpu_stime[nr_cpus];//Memory pages and exchange information://Min_flt, Maj_flt number of secondary pages of the cumulative process (Copy on write and anonymous pages) and the number of main page pages (from the mapping file or interchange//the number of pages that the device reads); Nswap records the number of pages that the process accumulates, that is, the number of pages written to the switching device. //Cmin_flt, Cmaj_flt, Cnswap records the cumulative number of page faults for all descendants of the ancestor process, the number of main pages and the number of pages swapped out. //when the parent process recycles the terminated child process, the parent process accumulates this information for the child process into those domains of its own structureUnsignedLongMin_flt, Maj_flt, Nswap, Cmin_flt, Cmaj_flt, Cnswap;intSwappable:1;//indicates whether the virtual address space of the process allows swapping out//Process authentication Information//Uid,gid is the user identifier and group identifier of the user running the process, usually the uid,gid of the process creator//euid,egid for effective Uid,gid//fsuid,fsgid for file system Uid,gid, these two ID numbers are usually equal to valid uid,gid, check for file//use them when accessing the system. //Suid,sgid for backup Uid,giduid_t uid,euid,suid,fsuid;gid_t Gid,egid,sgid,fsgid;intngroups;//How many user groups the recording process is ingid_t Groups[ngroups];//record the group in which the process resides//The power of the process, respectively, is the set of valid bits, the set of inherited bits, the allowed bit setkernel_cap_t cap_effective, cap_inheritable, cap_permitted;intKeep_capabilities:1;structUser_struct *user;structRlimit Rlim[rlim_nlimits];//process-related resource throttling informationUnsigned ShortUsed_math;//whether to use the FPUCharcomm[ -];//executable file name of the process being run//File System InformationintLink_count, Total_link_count;//NULL if no TTY process is located in the control terminal, if the control terminal is not required, then the pointer is emptystructTty_struct *tty;unsignedintlocks;//Inter-process communication informationstructSem_undo *semundo;//all undo actions on the semaphore by the processstructSem_queue *semsleeping;//When the process is suspended because of a semaphore operation, he logs the pending action in that queue//CPU State of the process, when switching, to be saved to the task_struct of the stop processstructthread_struct thread; //File System InformationstructFs_struct *FS; //Open File InformationstructFiles_struct *files; //Signal Processing Functionsspinlock_t Sigmask_lock;structSignal_struct *sig;//Signal Processing Functionssigset_t blocked;//the signal that the process is currently blocking, and each signal corresponds to one bitstructSigpending pending;//whether the process is waiting for a signal to be processedUnsignedLongsas_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;};
View Code(4) Form of PCB

The system has a large number of PCB, corresponding to a number of processes, then how these PCB organization? Generally there are two ways of organizing: linking and indexing. The common denominator of both approaches is that the PCB being executed has an execution pointer pointing to it. The difference is that the link-like readiness queue, blocking queue, and so on, are organized by means of pointer linking. When the process switches, take the ready queue pointer directly, because it points to the currently highest-priority ready PCB, and then the ready-queue pointer points to the next PCB it points to. Indexed ready queue, blocking queue, etc., organized by a table, the ready queue pointer points to the first piece of data in the table. This table is essentially an array of pointers, and the first pointer is, of course, the highest-priority ready process.

v. Process Control

What is Process Control? The essence is the control of the switching process state. is generally implemented by the primitives in the operating system. The primitive is a set of instructions that has the attribute "atomic manipulation", which, in other words, is a collection of these instructions, either all executed or not executed. There are also differences between the primitives of different operating systems.

(1), Process creation

A process may be created by the system kernel to receive a request, or it may be created by the process itself, and a process created by the process itself is typically a child process that inherits all the resources owned by the parent process. The creation process is implemented by the process creation primitives , usually by the following steps:

(2), process termination

The termination of the process is performed by the operating system. When a process ends for various reasons, the operating system is notified. The operating system invokes the process termination primitive to terminate the corresponding process:

(3) Process blocking

The process's blocking is self-executing by the process itself. But when the process finds itself unable to continue executing, it actively calls the process block primitive and blocks itself:

(4) Process wake-up

The wake of a process is usually performed by another thread. However, other threads invoke the process wake primitive to wake the specified process because some events want the thread to execute:

  

It is important to note that process wake and process blocking are a pair of primitives that have the exact opposite effect. A blocked process must be awakened by a process to continue execution.

(5) Process suspend and activate

The process hangs on its own or other processes execution. Process activation is performed by another process. The process is very simple, do not draw:

1) Process hangs: If the process is ready for the activity, it will be changed to static readiness, and if the process is blocking the activity, it will change to a standstill block, and if the process is executing, let the scheduler reschedule.

(PS: The PCB of the process needs to be copied to the specified memory area because there is no pending queue)

2) Process activation: If the process is still ready, it will be changed to active readiness, if the process is still blocked, it will be changed to active blocking;

Reference: "Computer operating System (Tong)"

My OS review-process (UP)

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.