Attempting to launch multiple process of infinite loops

I'm trying to write a program which will accept an int argument and launch that many process of infinite loops displaying the process number every second. I got my code a little more cleaned up. I manage to get all the process to run but how do i make it an infinite while loop for each process?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
//  main.cpp
//  HW1
//
//  Created by Bryant Sahota on 7/6/18.
//  Copyright © 2018 Bryant Sahota. All rights reserved.
//


#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <vector>

int main(int argc, const char * argv[]) {
    //number of process to launch
    int numProcess = 5; //atoi(argv[0]);
    int ProcessNumK = 0;
    //pid
    pid_t processID;
    for(int i = 0; i < numProcess; i++)
    {
        processID = fork();
        if(processID == 0)
        {
            while(true)
            {
                std::cout << "Process " + std::to_string(i) + " running. " << std::endl;
                exit(0);
            }
        }
    }
}
Last edited on
Topic archived. No new replies allowed.