0. System ();
The system () function calls the shell program to execute the command (low efficiency), which is equivalent to fork (), then Execve (); Features: The original process and the sub-process each run, and the original process needs to wait for the child process to run, and then continue;
1. Fork ();
References: Linux fork method to create multiple sub-processes simultaneously (i)
In Linux, you use fork () to create multiple sub-processes with a parent process in the following format:
1 intStatus,idx;2 3 for(idx =0; IDX <Ten; idx++) {4Status =fork ();5 if(Status = =0|| Status = =-1) Break;//each time the loop is discovered, the child process is found to jump directly from the loop that created the child process, not letting you go into the loop, which ensures that only the parent process does the work of looping through the creation of the child process at a time6 }7 8 if(Status = =-1) {9 //ErrorTen}Else if(Status = =0) {//code to be executed by each child process One //Sub Process A}Else { - //Parent Process -}
Reference: Process Control: Fork in Linux creating multiple sub-processes at the same time considerations
/*You can not create a child process here, you want to create-"judge-" use-"return or exit. Not much more like test2.c *childpid1 = fork (); *childpid2 = fork (); *CHILDPID3 = fork (); */Childpid1= Fork ();//Create if(0= = CHILDPID1)//Judging{//Enterprintf"In child1 process\n"); printf ("\tchild pid =%d\n", Getpid ()); Exit (exit_success); //Exit}
2. exec* ();
Reference documents:
Linux system Programming Process (V): EXEC series functions
EXECL Learning under Linux
Errors in the compilation:
Warning:not enough variables to fit a sentinel appears when using the Execl () function
Workaround-Adjust the parameters in the EXECL
Creation of processes under Linux (System (); Fork (); exec* ())