[Study record]fork stress test program

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.