// Test that thrd succeeds or fails gracefully. // This file was modified from the xv6-based forktest.c // 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 10 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 thrdf(uint64 thrdnum) { print("Hello from thread #"); printdec((int)thrdnum); print("\n"); int i, j, ch, pr; pr = 7-(getpid() % 4); ch = '0'+pr; prio(getpid(), pr, 4); //sleep(1); for (i = 0; i < 100; i++) { for (j = 0; j < 256; j++) { ch++; } char str[2]; str[0] = (char)ch; str[1] = 0; print(str); } exit(0); } void thrdtest(void) { int n, pid; print("thrd test\n"); print("thrdf is at "); printdec((int)(uint64)&thrdf); print("\n"); //print("testing printdec(12345)="); printdec(12345); print("\n"); print("attempting to launch up to N="); printdec(N); print(" processes in the same address space...\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("\nthrd() test OK\n"); } int main(void) { thrdtest(); exit(0); }