Basic multi-process test framework for "Linux learning"

Source: Internet
Author: User

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"

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.