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.
|
|
|
|
|
2019-06-11 09:57:14 -04:00
|
|
|
#include "user/user.h"
|
2007-08-24 20:20:23 +00:00
|
|
|
|
2024-06-15 16:55:06 +02:00
|
|
|
#define N 1000
|
2010-07-02 14:51:53 -04:00
|
|
|
|
2007-08-24 20:20:23 +00:00
|
|
|
void
|
2019-08-27 13:13:03 -04:00
|
|
|
print(const char *s)
|
2007-08-24 20:20:23 +00:00
|
|
|
{
|
2019-08-27 13:13:03 -04:00
|
|
|
write(1, s, strlen(s));
|
2007-08-24 20:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
forktest(void)
|
|
|
|
{
|
|
|
|
int n, pid;
|
|
|
|
|
2019-08-27 13:13:03 -04:00
|
|
|
print("fork test\n");
|
2007-08-24 20:20:23 +00:00
|
|
|
|
2024-06-15 16:55:06 +02:00
|
|
|
for(n = 0; n < N; n++) {
|
2007-08-24 20:20:23 +00:00
|
|
|
pid = fork();
|
|
|
|
if(pid < 0)
|
|
|
|
break;
|
|
|
|
if(pid == 0)
|
2019-09-10 12:30:10 -04:00
|
|
|
exit(0);
|
2007-08-24 20:20:23 +00:00
|
|
|
}
|
2016-08-25 09:13:00 -04:00
|
|
|
|
2024-06-15 16:55:06 +02:00
|
|
|
if(n == N) {
|
2019-08-27 13:13:03 -04:00
|
|
|
print("fork claimed to work N times!\n");
|
2019-09-11 10:04:40 -04:00
|
|
|
exit(1);
|
2007-08-24 20:20:23 +00:00
|
|
|
}
|
2016-08-25 09:13:00 -04:00
|
|
|
|
2024-06-15 16:55:06 +02:00
|
|
|
for(; n > 0; n--) {
|
|
|
|
if(wait(0) < 0) {
|
2019-08-27 13:13:03 -04:00
|
|
|
print("wait stopped early\n");
|
2019-09-11 10:04:40 -04:00
|
|
|
exit(1);
|
2007-08-24 20:20:23 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-25 09:13:00 -04:00
|
|
|
|
2024-06-15 16:55:06 +02:00
|
|
|
if(wait(0) != -1) {
|
2019-08-27 13:13:03 -04:00
|
|
|
print("wait got too many\n");
|
2019-09-11 10:04:40 -04:00
|
|
|
exit(1);
|
2007-08-24 20:20:23 +00:00
|
|
|
}
|
2016-08-25 09:13:00 -04:00
|
|
|
|
2019-08-27 13:13:03 -04:00
|
|
|
print("fork test OK\n");
|
2007-08-24 20:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
forktest();
|
2019-09-10 12:30:10 -04:00
|
|
|
exit(0);
|
2007-08-24 20:20:23 +00:00
|
|
|
}
|