forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rsc
committed
Aug 24, 2007
1 parent
5af5f6a
commit e0e7d07
Showing
3 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters