forktest.c
来自「美国mit操作系统课程所用的一个教学操作系统xv6」· C语言 代码 · 共 55 行
C
55 行
// Test that fork fails gracefully.// Tiny executable so that the limit can be filling the proc table.#include "types.h"#include "stat.h"#include "user.h"voidprintf(int fd, char *s, ...){ write(fd, s, strlen(s));}voidforktest(void){ int n, pid; printf(1, "fork test\n"); for(n=0; n<1000; n++){ pid = fork(); if(pid < 0) break; if(pid == 0) exit(); } if(n == 1000){ printf(1, "fork claimed to work 1000 times!\n"); exit(); } for(; n > 0; n--){ if(wait() < 0){ printf(1, "wait stopped early\n"); exit(); } } if(wait() != -1){ printf(1, "wait got too many\n"); exit(); } printf(1, "fork test OK\n");}intmain(void){ forktest(); exit();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?