10th Lesson-Process Control

Source: Internet
Author: User

I. A process is a run-time activity of a program with independent functionality.
Two. Features:
(1) Dynamic nature
(2) Async
(3) Independence
(4) Concurrency
Three. Three states:
1. Ready: Only one process is running on the CPU at any time, but multiple processes are ready at the same time. The ready process is picked up by a certain algorithm and then handed to the CPU for execution.
2. Execution: When the process is dispatched, it enters the execution state.
3. Blocking: The process request is temporarily not satisfied, is blocking the state.
4. This will return to the ready state after blocking and executing, waiting for the next schedule.

Four. Process ID: Used to identify the process. ------PID
Parent Process-----PPID
User ID--------UID of the START process
Five. Process Mutex
Several processes access the same resource at the same time, but this resource allows only one process to access him at any given time. The other resources must wait. Until the process that occupies the release of the resource releases him.
Six. Critical resources
A resource that allows only one process to access at the same time in the operating system is called a critical resource.
Seven. Critical section:
The code that accesses critical resources in a process is called a critical section. In order to achieve mutually exclusive access to critical resources, it is necessary to ensure that many processes are mutually exclusive into their critical regions.
Eight. Process synchronization: A process in which a group of processes executes in a certain order is the process of synchronizing between processes. This set of processes with a synchronous relationship is called a cooperative process.
Nine. Process scheduling: According to a certain algorithm, from a set of ready-to-use process to choose a CPU run.
Ten. Scheduling algorithm:
(1)

(2) According to scheduling timing, scheduling can be divided into preemptive scheduling and non-preemptive scheduling. These two rules and the previously mentioned four scheduling algorithm together determine the operating system in the process scheduling.
11. Deadlocks: The deadlock that multiple processes have created because of competing resources. Cause these processes to continue to execute forward.

12. Getpid

13. Function Learning
4.1 Create a process
4.1. 1 Name of function
Fork
4.1.2 Function prototype
pid_t fork (void);
4.1.3 Function function
Create a child process
4.1.4 Owning header file
<unistd.h>
4.1.5 return value
success: Returns the PI of the child process in the parent process
returns 0 in a child process
failed: Return 1 in parent process
4.1.6 Parameter Description
No


4.1.7: How it works: The parent process calls fork to produce a child process that creates a space in memory, with the same code as the parent process, except that she does not start from the start address, but executes from the code behind the fork. Usually the parent process executes first, but not necessarily who is first. The child process executes again. The process PID can be used to differentiate between parent and child processes. Greater than 0 is the parent process. The corresponding sub-processes have their own separate data segments and stacks. Not shared with the parent process.


4.2 Create a process
4.2. 1 Name of function
vfork
4.2.2 Function prototype
pid_t vfork (void);
4.2.3 Function function
Create a child process and block the parent process
4.2.4 Owning header file
<sys/types.h>
<unistd.h>
4.2.5 return value
success: The PID of the child process is returned in the parent process
returns 0 in a child process
failed: Return 1 in parent process
4.2.6 Parameter Description
No
4.2.7: After creation, the child process must first run. However, the data segments and stacks are shared with the parent process.


4.2.8: Process exit: void exit (int var)
the parent process exits with return and exit, but the child process can only use exit. Normally, exit with exit (0), exit unexpectedly with exit (1)




4.3 process Wait4.3. 1 Name of function
Wait4.3.2 Function prototype
pid_t Wait (int *status);4.3.3 Function function
suspends the process that invokes it until its child process ends4.3.4 Owning header file
<sys/types.h><sys/wait.h>
4.3.5 return valuesuccess: Returns the PID of the terminated child process
failed: -14.3.6 Parameter Description
Status: Records the exit status of the child process.


4 . 4 Execute the program

4 . 4 . 1 function Names execl
4.4.2 Function prototype int execl (const char *path, const char *arg, ...);
4.4.3 function function Run the executable file
4.4.4 Owning header file <unistd.h>
4.4.5 return value success: Do not return
failed: returned-1. And the macro definition errno will be set. 4.4.6 Parameter Description
paths: The path to the executable program to run, although it is always included in the file, the second parameter that follows will also indicate the file you want to run. Arg: And the parameters that follow are the parameters that are required for the executable file to run. The null pointer is encountered and must be null at the end.
4.4.7 after calling Execl, the code snippet changes, preserving the original PID, not generating a new process, and executing the new code. But fork is to keep the original code and generate a new PID.

10th Lesson-Process Control

Related Article

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.