Advertisement
Tobiasz931

rozprochowość trzecia

Mar 21st, 2013
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. int znajdz(int * tab, int tabnumb){
  5.     int i = 0;
  6.     while(i<tabnumb && tab[i] == -1)
  7.         i++;
  8.     if ( i == tabnumb)
  9.         return -1;
  10.     return i;
  11. }
  12. int main(int argc, char* argv[]){
  13.     int tab[100];
  14.     int tabnumb = argc - 1;
  15.     int i,j;
  16.     int pid;
  17.     int procnumb;
  18.     int mothership = 1;
  19.     for(i=1;i<argc;i++){
  20.         tab[i-1] = atoi(argv[i]);
  21.         tab[i] = -1;
  22.     }
  23.     procnumb = tab[0];
  24.     tab[0] = -1;
  25.     i = 0;
  26.     while(i < procnumb){
  27.         if(procnumb > 0)
  28.             pid = fork();
  29.         if(pid == 0){
  30.             i = 0;
  31.             j = znajdz(tab, tabnumb);
  32.             if(j== -1)
  33.                 procnumb = -1;
  34.             else{
  35.                 procnumb = tab[j];
  36.                 tab[j] = -1;
  37.             }
  38.             mothership = 0;
  39.         }
  40.         else{
  41.             i++;
  42.         }
  43.     }
  44.     if(mothership == 1){
  45.         sleep(1);
  46.         eprocnumbeclp( "ps", "-u student", "--forest", NULL );
  47.     }else
  48.         sleep(5);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement