2007-08-24 20:20:23 +00:00
|
|
|
// 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"
|
|
|
|
|
2010-07-02 18:51:53 +00:00
|
|
|
#define N 1000
|
|
|
|
|
2007-08-24 20:20:23 +00:00
|
|
|
void
|
|
|
|
printf(int fd, char *s, ...)
|
|
|
|
{
|
|
|
|
write(fd, s, strlen(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
forktest(void)
|
|
|
|
{
|
|
|
|
int n, pid;
|
|
|
|
|
|
|
|
printf(1, "fork test\n");
|
|
|
|
|
2010-07-02 18:51:53 +00:00
|
|
|
for(n=0; n<N; n++){
|
2007-08-24 20:20:23 +00:00
|
|
|
pid = fork();
|
|
|
|
if(pid < 0)
|
|
|
|
break;
|
|
|
|
if(pid == 0)
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2010-07-02 18:51:53 +00:00
|
|
|
if(n == N){
|
|
|
|
printf(1, "fork claimed to work N times!\n", N);
|
2007-08-24 20:20:23 +00:00
|
|
|
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();
|
|
|
|
}
|