Advertisement
diegoaguilar

runsim

Feb 23rd, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <limits.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <sys/types.h>
  6. #include <sys/wait.h>
  7. #include <errno.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10.  
  11. char makeargv(char *caracteres)
  12. {
  13.     char argumentos[3][30];
  14.     int i=0,j=0;
  15.     while(*caracteres!='\0')
  16.     {
  17.         if(*caracteres==' ')
  18.          j++;
  19.         argumentos[j][i++]=*caracteres++;;
  20.     }
  21.     return argumentos;
  22. }
  23. int main(int argc, char *argv[])
  24. {
  25.  
  26.  int i,n, status, pr_limit, pr_count=0;
  27.  char cadena[MAX_CANON],argumentos[3][100];
  28.  if (isdigit(argv[1])==0)
  29.  {
  30.      fprintf(stderr, "ERROR FATAL");
  31.      exit(0);
  32.  }
  33.  pr_limit=atoi(argv[1]);
  34.  pid_t childpid;
  35.  
  36.  FILE *fd;
  37.  fd=fopen( "testsim.data", "r");
  38.  for(i=1; i<pr_limit; i++)
  39.  
  40.  {
  41.    
  42.  
  43.  
  44.  if (pr_count==pr_limit)
  45.  {wait(&status);
  46.  pr_count--;
  47.  }
  48.   fgets(cadena,MAX_CANON,fd);
  49.   argumentos=makeargv(cadena);
  50.   switch(fork())
  51.   {
  52.       case -1: exit(0);
  53.       case 0: break;
  54.       default: execvcp(argumentos[0],argumentos);
  55.      
  56.   }
  57. }
  58.  return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement