[USER] Exit and wait syscalls
This commit is contained in:
26
init/init.c
26
init/init.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user