The second process of the second chapter of the operating system

process control

process control basic process: Process creation Termination of the process Process blocking and waking up The hang of the process and activation of the

kinship of the process:   The processes running in the system are not all isolated. After some processes run, other processes are called to execute, thus forming a parent-child relationship between processes.   A "process map" can be used to describe the family relationship of a process, which is actually a directed tree.   The parent-child relationship between processes is related to the inheritance of resources. When a process is created and revoked, its parent and child processes are affected accordingly.

1. Creation of the process   (1) A process creates another event (reason)   User login: User's request in time sharing   Job scheduling: batch processing   Provide service: The running user program makes a function request to create a service process (such as a print service)   Application request: The application creates its own process and completes a new process for a specific function. (trojan program)   (2) the creation process (very critical, can not be interrupted)   - Apply for a blank PCB   - Allocating resources for new processes: mainly processing of memory resources   - Initialize the process control block: the identifier (including the parent process), the program counter points to the program entry address, the ready state, the priority, etc.   - Insert the new process into the ready queue

2. The termination of the process   (1) Events that cause the process to terminate   - Normal end   - Abnormal end:   Memory out of bounds error   Protection error (permission error, such as modifying read-only files, etc.)   Illegal instruction (an instruction that does not exist, the program is abnormally turned and the data is used as an instruction)   Privileged instruction error (user mode program attempts to execute only OS executable instructions)   Run timeout, operation error, i/o failure, etc.   - outside intervention   Operator or operating system intervention (when deadlocked, it can be artificially terminated)   The parent process requests to terminate the child process   The parent process terminates and the descendant process terminates   (2) termination process   For the above events, the OS calls the kernel to terminate the primitives and performs the following process:   - According to the process identifier, retrieve the process PCB and read its status.       *IF execution state, immediately terminate the process, set the scheduling flag to true, indicating re-scheduling.       *IF has a descendant process and should be terminated in case it becomes an uncontrollable process.   - Return all resources to their parent process or system.   - Remove the process PCB from the queue or linked list

3. Blocking and waking up the process   (1). Events that cause process blocking and wake-up   Request for system service satisfaction   Start some kind of wait (I/O) operation   New data required for cooperation has not yet arrived   A process that performs a function temporarily has no new work to do (such as sending a data process)   (2). Blocking and waking process   It is an active behavior to block the primitive by the process call blocking:   - Change the state in the PCB to blocking   - the PCB is added to the blocking queue   - Transfer process scheduling, assign processor to another process   - Perform process switching, that is, protect and reset the processor state according to the PCB of the two switching processes. Blocking is the opposite of awakening primitives. When a pair of events is used in a blocking process, the process (such as a process that abandons the resource) calls the wakeup primitive to wake up the process waiting for the event.   - remove the blocking process from the blocking queue waiting for the event   - Change the current status in its PCB to Ready   - Insert the PCB into the ready queue.

4. Suspend and activate the process   The state of the process, the activity is ready to be statically ready, and the active blocking is changed to static blocking.       Suspending primitives suspends the specified process or blocking process.   (1) Check the status of the suspended process, if the activity is ready, it will be changed to static ready, and if the activity is blocked, it will be changed to static blocking.   (2) Copy the PCB to the memory (for easy inspection) / external storage (for swapping) the specified area   (3) * If the suspended process is in the execution state, the process scheduling needs to be re-executed.   Note: The process can only suspend itself or its descendants.   The execution process of the activation primitive:   - If the suspended process is on external storage, transfer it to memory   - Check the status of the process. If it is at rest, it will be ready for activity. If it is at rest, it will be changed to active blocking.   About scheduling:   - In process control, state transitions and scheduling are closely related.   - changes in the running state process must produce scheduling behavior   - As long as a new ready state process is generated, the scheduling strategy needs to be considered   As long as the preemptive scheduling is used, it is necessary to check whether the new ready process can preempt the CPU and cause a new scheduling.