21 lines
468 B
C++
21 lines
468 B
C++
using namespace std;
|
|
#include <iostream>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
int main(int argc, char * argv[])
|
|
{
|
|
pid_t x;
|
|
cout << "The pid of the parent is " << getpid() << endl;
|
|
for(int i=0; i<10; i++){
|
|
x = fork();
|
|
if (x == 0 ) /* we are the child */
|
|
{
|
|
cout << "Id: " << getpid() << "\tX: x "<< endl;
|
|
exit(0);
|
|
}
|
|
// cout << "I am the parent, the child's pid is " << x << endl;
|
|
}
|
|
exit(0);
|
|
}
|