Topic:
Programming a basic multi-process test framework that prompts the user to enter the number of processes, and the number of running laps per process. Perform multi-process stress testing.
Requires the parent process to monitor the exit of all child processes and avoid the zombie process.
#include <stdio.h>#include<unistd.h>#include<unistd.h>#include<stdlib.h>#include<sys/types.h>#include<sys/wait.h>voidFuncint,int);intMainvoid){ intNUMJ; intNumq; intI, J; pid_t pid; printf ("parent Process PID%d\n", Getpid ()); printf ("Please enter the number of processes you need to create:"); scanf ("%d", &NUMJ); printf ("Please enter how many laps each process needs to run:"); scanf ("%d", &numq); for(i =0; i < NUMJ; ++i) {pid=Fork (); if(-1==pid) {Exit (0); } if(0==pid) { for(j =0; J < Numq; ++j) {func (I, J); } exit (0); } } intChlidpid; while(Chlidpid = Waitpid (-1Null0)) >0) {printf ("Child pid:%d\n", Chlidpid); } printf ("parent process end \ n"); return 0;}voidFuncintIintj) {printf ("process%d, section%d \ n", i +1, J +1); return;}
Basic multi-process test framework for "Linux learning"