summaryrefslogtreecommitdiff
path: root/forktest.c
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-24 20:20:23 +0000
committerrsc <rsc>2007-08-24 20:20:23 +0000
commite0e7d07e5afc1a073b659cbf0b8594071f05a816 (patch)
treeca49d4be6d276c241ef2fff485c34b72090ce0f0 /forktest.c
parent5af5f6aa7f52db85f0f22555ae39395dbe68b731 (diff)
downloadxv6-labs-e0e7d07e5afc1a073b659cbf0b8594071f05a816.tar.gz
xv6-labs-e0e7d07e5afc1a073b659cbf0b8594071f05a816.tar.bz2
xv6-labs-e0e7d07e5afc1a073b659cbf0b8594071f05a816.zip
test that fork fails gracefully
Diffstat (limited to 'forktest.c')
-rw-r--r--forktest.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/forktest.c b/forktest.c
new file mode 100644
index 0000000..90cc38c
--- /dev/null
+++ b/forktest.c
@@ -0,0 +1,54 @@
+// 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"
+
+void
+printf(int fd, char *s, ...)
+{
+ write(fd, s, strlen(s));
+}
+
+void
+forktest(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");
+}
+
+int
+main(void)
+{
+ forktest();
+ exit();
+}