-
Notifications
You must be signed in to change notification settings - Fork 0
/
p1.cpp
41 lines (38 loc) · 822 Bytes
/
p1.cpp
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
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<pid_t> proID;
auto pid1 = fork();
if(pid1 == 0){
cout << "pid1:" << getpid() << endl;
for(int i = 0; i < 12; i++){
//system("whoami");
}
}else{
proID.push_back(pid1);
}
auto pid2 = fork();
if(pid2 == 0){
cout << "pid2:" << getpid() << endl;
}else{
proID.push_back(pid2);
}
auto pid3 = fork();
if(pid3 == 0){
cout << "pid3:" << getpid() << endl;
}else{
proID.push_back(pid3);
}
if(pid3 != 0){
cout << "**********\n";
for(int i = 0; i < proID.size(); i++){
cout << proID[i] << endl;
}
}
return 0;
}