Xv6 with picoc & Linkage editor  v1.0
The project delineate mutual cohesion between c library, linkage editor ( linker), interpreter and operating system by porting the same on xv6 kernel
forktest.c
00001 // Test that fork fails gracefully.
00002 // Tiny executable so that the limit can be filling the proc table.
00003 
00004 #include "types.h"
00005 #include "stat.h"
00006 #include "user.h"
00007 
00008 #define N  1000
00009 
00010 int
00011 printf(char *s, ...)
00012 {
00013   return write(1, s, strlen(s));
00014 }
00015 
00016 void
00017 forktest(void)
00018 {
00019   int n, pid;
00020 
00021   printf( "fork test\n");
00022 
00023   for(n=0; n<N; n++){
00024     pid = fork();
00025     if(pid < 0)
00026       break;
00027     if(pid == 0)
00028       exit(1);
00029   }
00030   
00031   if(n == N){
00032     printf( "fork claimed to work N times!\n", N);
00033     exit(1);
00034   }
00035   
00036   for(; n > 0; n--){
00037     if(wait() < 0){
00038       printf( "wait stopped early\n");
00039       exit(1);
00040     }
00041   }
00042   
00043   if(wait() != -1){
00044     printf( "wait got too many\n");
00045     exit(1);
00046   }
00047   
00048   printf( "fork test OK\n");
00049 }
00050 
00051 int
00052 main(void)
00053 {
00054   forktest();
00055   exit(1);
00056 }
 All Data Structures