~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Minix Cross Reference
Minix/test/test4.c


  1 /* test 4 */
  2 
  3 #include <sys/types.h>
  4 #include <sys/wait.h>
  5 #include <fcntl.h>
  6 #include <signal.h>
  7 #include <stdlib.h>
  8 #include <unistd.h>
  9 #include <stdio.h>
 10 
 11 pid_t pid0, pid1, pid2, pid3;
 12 int s, i, fd, nextb, errct = 0;
 13 char *tempfile = "test4.temp";
 14 char buf[1024];
 15 
 16 _PROTOTYPE(int main, (void));
 17 _PROTOTYPE(void subr, (void));
 18 _PROTOTYPE(void nofork, (void));
 19 _PROTOTYPE(void quit, (void));
 20 
 21 int main()
 22 {
 23   int k;
 24 
 25   printf("Test  4 ");
 26   fflush(stdout);               /* have to flush for child's benefit */
 27 
 28   system("rm -rf DIR_04; mkdir DIR_04");
 29   chdir("DIR_04");
 30 
 31   creat(tempfile, 0777);
 32   for (k = 0; k < 20; k++) {
 33         subr();
 34   }
 35   unlink(tempfile);
 36   quit();
 37   return(-1);                   /* impossible */
 38 }
 39 
 40 
 41 void subr()
 42 {
 43   if ( (pid0 = fork()) != 0) {
 44         /* Parent 0 */
 45         if (pid0 < 0) nofork();
 46         if ( (pid1 = fork()) != 0) {
 47                 /* Parent 1 */
 48                 if (pid1 < 0) nofork();
 49                 if ( (pid2 = fork()) != 0) {
 50                         /* Parent 2 */
 51                         if (pid2 < 0) nofork();
 52                         if ( (pid3 = fork()) != 0) {
 53                                 /* Parent 3 */
 54                                 if (pid3 < 0) nofork();
 55                                 for (i = 0; i < 10000; i++);
 56                                 kill(pid2, 9);
 57                                 kill(pid1, 9);
 58                                 kill(pid0, 9);
 59                                 wait(&s);
 60                                 wait(&s);
 61                                 wait(&s);
 62                                 wait(&s);
 63                         } else {
 64                                 fd = open(tempfile, O_RDONLY);
 65                                 lseek(fd, 20480L * nextb, 0);
 66                                 for (i = 0; i < 10; i++) read(fd, buf, 1024);
 67                                 nextb++;
 68                                 close(fd);
 69                                 exit(0);
 70                         }
 71                 } else {
 72                         while (1) getpid();
 73                 }
 74         } else {
 75                 while (1) getpid();
 76         }
 77   } else {
 78         while (1) getpid();
 79   }
 80 }
 81 
 82 void nofork()
 83 {
 84   printf("Fork failed.  Not enough memory.\n");
 85   exit(1);
 86 }
 87 
 88 void quit()
 89 {
 90 
 91   chdir("..");
 92   system("rm -rf DIR*");
 93 
 94   if (errct == 0) {
 95         printf("ok\n");
 96         exit(0);
 97   } else {
 98         printf("%d errors\n", errct);
 99         exit(1);
100   }
101 }
102 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.