/** Title: * Programming a basic multi-process test framework, prompting the user to enter the number of processes, and the number of running laps per process. (fork) * For multi-process stress testing. (EXECVE) * requires the parent process to monitor the exit of all child processes and avoid the zombie process. (wait) **/#include<stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<errno.h>#include<sys/types.h>#include<sys/wait.h>intMainintArgChar*args[]) { if(Arg <2) {printf ("Please print pid num!\n"); return-1; } intPidnum = Atoi (args[1]); intPID =0; while(pidnum--) {PID=Fork (); if(PID <0) {printf ("Fork () failed!\n"); Break; } if(PID = =0) { //Execute the test programEXECL ("./runc","./runc", NULL); } } intStatus =0, ret =0; while(1) {ret= Wait (&status); printf ("Child process pid=%d\n", ret); if(ret = =-1) { //Shielding Other signals if(errno = =eintr) { Continue; } Break; }} printf ("game is over!\n"); return 0;}
Linux Linux program exercise 14 (Multi-process stress test)