Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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"
- #define N 1000
- void
- heavytest()
- {
- int i, j;
- for(i = 1; i < 1000000000; i++){
- j++;
- }
- }
- void
- forktest(void)
- {
- int n, pid;
- printf(1, "fork test\n");
- for(n=0; n<N; n++){
- pid = fork();
- if(pid < 0)
- break;
- if(pid == 0)
- exit();
- // For priority testing
- if(n == 10){
- printf(1, "\n* Heavy test on pid %d\n", pid);
- set_priority(2);
- procstat();
- heavytest();
- }
- if(n == 40){
- printf(1, "\n* Heavy test on pid %d\n", pid);
- set_priority(0);
- procstat();
- heavytest();
- }
- }
- if(n == N){
- printf(1, "fork claimed to work %d times!\n", 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();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement