Linux Linux program Exercise 14 (Multi-process stress test)

Source: Internet
Author: User

/** 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)

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.