user/forktest.c
56 lines
1// Test that fork fails gracefully.2// Tiny executable so that the limit can be filling the proc table.34#include "kernel/types.h"5#include "kernel/stat.h"6#include "user/user.h"78#define N 1000910void11print(const char *s)12{13 write(1, s, strlen(s));14}1516void17forktest(void)18{19 int n, pid;2021 print("fork test\n");2223 for(n=0; n<N; n++){24 pid = fork();25 if(pid < 0)26 break;27 if(pid == 0)28 exit(0);29 }3031 if(n == N){32 print("fork claimed to work N times!\n");33 exit(1);34 }3536 for(; n > 0; n--){37 if(wait(0) < 0){38 print("wait stopped early\n");39 exit(1);40 }41 }4243 if(wait(0) != -1){44 print("wait got too many\n");45 exit(1);46 }4748 print("fork test OK\n");49}5051int52main(void)53{54 forktest();55 exit(0);56}57