// Test that fork fails gracefully. // Tiny executable so that the limit can be filling the proc table. #include "kernel/types.h" #include "kernel/stat.h" #include "user/user.h" // N should be set HIGHER than the limit! #define N 10000 void print(const char *s) { write(1, s, strlen(s)); } void printdec(unsigned int i) { if (i == 0) { print("0"); return; } char foo[11]; int idx = 10; while (i > 0) { idx--; foo[idx] = '0' + (i%10); i /= 10; } foo[10] = 0; print(foo+idx); } void forktest(void) { int n, pid; print("fork test\n"); //print("testing printdec(12345)="); printdec(12345); print("\n"); print("attempting to fork up to N="); printdec(N); print(" processes...\n"); for(n=0; n 0; n--){ if(wait(0) < 0){ print("wait stopped early\n"); exit(1); } } if(wait(0) != -1){ print("wait got too many\n"); exit(1); } print("fork test OK\n"); } int main(void) { forktest(); exit(0); }