int status;pid_t t = fork (), if (t) {waitpid (T, &status, 0);} else{System ("VI temp.txt"); Exit (0);} After both the parent and child processes have finished executing the parsing process: if and else or select branch.
The main reason is that thefork () function is called once and returned two times . The difference of two returns is that the return value of the child process is 0, and the parent process returns the process ID of the new child process. When returned, the parent process executes waitpid (t, &status, 0) waiting for the child process to end, and the child process enters another branch to execute system ("VI temp.txt"); exit (0); This code can be described as the parent process and the child process have performed a single judgment.
Use fork () to create a child process under Linux and cause the parent process to wait for the child process to end