[USER] Exit and wait syscalls

This commit is contained in:
2017-02-24 15:30:45 +01:00
parent 5e4946e8e4
commit e3e661e7e5
6 changed files with 76 additions and 9 deletions

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;
}