-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExeB.c
More file actions
30 lines (26 loc) · 670 Bytes
/
ExeB.c
File metadata and controls
30 lines (26 loc) · 670 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main(void){
int i, tmp;
pid_t pid[4];
pid_t father=getpid(); //krataei to pid tou patera
for (i=0;i<4;i++) {
pid[i] = fork();
if (pid[i] == 0) {//ta paidia kanoun break
break;
}
}
if (getpid()==father) {
// an einai o pateras
for(i=0;i<4;i++) {
wait(&tmp);//perimene ta paidia
}
printf("Eimai o pateras [pid: %d, ppid: %d]\n",getpid(),getppid());
} else {
// paidi
printf("Eimai to paidi me pid: %d,kai exw patera me ppid: %d]\n",getpid(),getppid());
}
return 0;
}