The only way to create a process is to use the system call fork. The core is to complete the fork system call in several steps:
1: assign a table item to the new process. The number of processes that a user can run at the same time is limited. This limit is not imposed on Super Users, but it cannot exceed the maximum number of table items in the table.
2: Give the sub-process a unique process identifier PID. The process identifier is actually the index number of the table item in the progress table.
3: copy the table entry of a parent process to the child process. The process entry of the core initialization sub-process is copied from the parent process. Therefore, sub-processes have the same uid, EUID, GID, nice value used for priority calculation, current directory, current root, user file descriptor table, and so on as the parent process.
4: add the reference numbers of files connected to the parent process and the index node table. 1. These files are automatically connected to the child process.
5: the core is to create a user-level context for the child process. The core is to allocate memory for the U zone, zone, and auxiliary page table of the child process, and copy the content of the parent process zone. This generates the static part of the process;
6: generate the dynamic part of the process. The core copies the first layer of the context of the parent process, that is, the register context and core stack. The core then virtual a context layer for the child process, this is to enable the sub-process to "Restore" its context. At this time, the call will return the child process PID to the parent process, and the child process will return 0.