1
0
UAHCode/CPE435/Lab2/lab2_ex3.cpp
2022-08-28 16:12:16 -05:00

29 lines
607 B
C++

using namespace std;
#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char * argv[])
{
int proc;
int x;
cout << "Please enter a number of processes to spawn: ";
cin >> proc;
if((proc % 2) != 0)
{
cout << "Odd number entered. Please enter an even number. Exiting now." << endl;
return(0);
}
for(int i=0; i<proc; i++){
x = fork();
if (x == 0 ) /* we are the child */
{
cout << "Id: " << getpid() << endl;
exit(0);
}
// cout << "I am the parent, the child's pid is " << x << endl;
}
//exit(0);
}