[USER] Exit and wait syscalls

This commit is contained in:
thomas committed 2017-03-27 23:09:09 +02:00
1 parent 5e4946e8e4
commit e3e661e7e5
6 files changed
+75 -8

No files matched your search

+18 -8
View File
@@ -1,22 +1,32 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main(int argc, char **argv)
{
(void) argc;
(void) argv;
int num = 5;
if(fork())
if(!fork())
{
num = 10;
printf("I am the parent! - %d\n", num);
} else {
num = 3;
printf("I am the child! - %d\n", num);
if(!fork())
return 200;
return 100;
}
for(int j=0; j <= 10; j++)
{
if(!fork())
return j;
}
while(1)
{
int retval;
int pid = wait(&retval);
printf("Pid: %d exited with %d\n", pid, retval);
}
for(;;);
return 0;
}