top
command.
forkCode
cp start.cpp working.cpp
OBJS
line in the Makefile
getpid
pid_t getpid(void);
pid_t myPid; myPid = getpid(); cout << "My pid is " << myPid << endl;
pid_t fork(void);
pid_t myPid; pid_t pid; pid = fork(); myPid = getpid(); if (pid == 0) { cout << "Child here, my pid is " << myPid << endl; } else { cout << "Parent here, my pid is " << myPid << endl; } for(i = 0; i < 10'000; ++i) {
const int PROCS{10}; .... pid_t pid; i = 0; while (i < PROCS) { pid = fork(); myPid = getpid(); if (pid == 0) { cout <<"Child here, my pid is " << myPid <<endl; i = PROCS; } else { cout << "Parent here, my pid is " << myPid << endl; i++; } }
i = PROCS;
in the child branch of the if.
bob hard nproc 150