Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include "hw2_syscalls.h"
  2. #include <assert.h>
  3. #include <sys/wait.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <sched.h>
  7. #include <errno.h>
  8. #ifndef errno
  9. extern int errno;
  10. #endif
  11.  
  12.  
  13.  
  14. int main() {
  15.     int res = 0;
  16.     int lp[3] = {0, 0, 0};
  17.     int lp2[3] = {0, 0, 0};
  18.     lp2[0] = 0;
  19.     lp2[1] = 0;
  20.     lp2[2] =0;
  21.     lp[0] = 0;
  22.     lp[1] = 600;
  23.     lp[2] =5;
  24.     sched_setscheduler(getpid(),5,&lp);
  25.     printf("remaining time father 1 %d\n",remaining_time(getpid()));
  26.     int father_pid = getpid();
  27.     if (fork() == 0) {
  28.         printf("remaining time father 2 %d\n",remaining_time(father_pid));
  29.         printf("cooloffs father %d\n",remaining_cooloffs(father_pid));
  30.         lp[0] = 0;
  31.         lp[1] = 2000;
  32.         lp[2] =4;
  33.         sched_setparam(father_pid,&lp);
  34.         exit(1);
  35.     }
  36.     printf("remaining time father 3 %d ~~ 300\n",remaining_time(getpid()));
  37.     while(is_SHORT(getpid()));
  38.     printf("remaining time overdue father %d ~~ 600\n",remaining_time(getpid()));
  39.     while(!is_SHORT(getpid()));
  40.     printf("remaining time father 4 %d ~~ 2000\n",remaining_time(getpid()));
  41.     if(fork()==0){
  42.         lp[0] = 0;
  43.         lp[1] = 2000;
  44.         lp[2] =0;
  45.         sched_setparam(getpid(),&lp);
  46.         printf("errno %d\n",errno);
  47.         printf("cooloffs father %d\n",remaining_cooloffs(father_pid));
  48.         printf("remaining time son1 %d\n",remaining_time(getpid()));
  49.         printf("cooloffs son %d == 1\n",remaining_cooloffs(getpid()));
  50.         printf("\nSON ENTERING OVERDUE\n");
  51.         while(is_SHORT(getpid()));
  52.         printf("cooloffs overdue son %d == 0\n",remaining_cooloffs(getpid()));
  53.         printf("\nSON EXITING OVERDUE\n");
  54.         while(!is_SHORT(getpid()));
  55.         printf("cooloffs overdue son %d == 0\n",remaining_cooloffs(getpid()));
  56.         printf("remaining time son1 %d ~~ 2000\n",remaining_time(getpid()));
  57.         printf("\nSON ENTERING OVERDUE\n");
  58.         while(is_SHORT(getpid()));
  59.         printf("remaining time son1 %d ~~ 0\n",remaining_time(getpid()));
  60.         exit(1);
  61.     }
  62.     printf("remaining time father 4 %d\n",remaining_time(father_pid));
  63.     int i=0;
  64.     for(;i<=500000000;i++){
  65.         if (!(i % 100000000)) {
  66.                 printf("father\n");
  67.                 printf("remaining time father %d\n",remaining_time(father_pid));
  68.         }
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement