#include <stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<errno.h>voidLoopfunc (int);intMainvoid){ intProcnum =0; intLoopnum =0; intI, J; pid_t pid; printf ("Please enter the number of processes to run"); scanf ("%d", &procnum); printf ("Please enter the number of laps per process"); scanf ("%d", &loopnum); for(i =0; i < Procnum; ++i) {pid=Fork (); if(-1==pid) {Perror ("Fork Err"); return 0; } if(PID >0) { ; } if(0==pid) { for(j =0; J < Loopnum; ++j) {Loopfunc (J+1); } return 0; }} printf ("over!\n"); return 0;}voidLoopfunc (intnum) {printf ("loopfunc......%d\n", num); return;}/*------------The child process ends after each loop does not participate in the next fork, the parent process continues to have children. Both the parent process and the child process are executed concurrently, and the parent process continues to go down after the child has finished. The child did his own thing, so the last word of printf ("over!\n ") may appear anywhere in the output statement this does not matter. If the parent process does not participate in the next fork and the child participates in the next fork, it forms 2 different form-forming parent processes that participate in the next fork to form a tree-like shape with a depth of one (one father, multiple children) The child process participates in the next fork to form the linked list shape (the child has children)------------*/
Copy to Google TranslateTranslation Results
[Study record]fork stress test program