BUT2/SCR/TP03/ex4.c

23 lines
392 B
C
Raw Normal View History

2023-10-12 16:39:49 +02:00
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
int pid = fork();
if (pid == -1) {
exit(0);
}
if (pid == 0) {
printf("fork = %d, pid = %d, ppid = %d\n",pid,getpid(),getppid());
sleep(4);
exit(2);
}
if (pid > 0) {
printf("fork = %d, pid = %d, ppid = %d\n",pid,getpid(),getppid());
printf("%d\n",wait());
exit(2);
}
}