Guest User

Untitled

a guest
Dec 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. void error_y_exit(char *msg, int exit_status)
  7. {
  8.     perror(msg);
  9.     exit(exit_status);
  10. }
  11.  
  12. void muta_a_EXPR(char *num1, char *num2)
  13. {
  14.    execlp("expr",num1,"*",num2,(char *) NULL);
  15.    error_y_exit("Ha fallado la mutacion al expr",1);
  16. }
  17.  
  18.  
  19. int main(int argc,char *argv[])
  20. {
  21.     char *buff;
  22.     char buffer[80];
  23.     int pid;
  24.     int i;    
  25.     int status;
  26.     char *num2 = argv[1];
  27.     for (i = 1; i <= 10;i++)
  28.     {
  29.         pid=fork();
  30.         switch (pid) {
  31.             case 0: /* Escribe aqui el codigo del proceso hijo */
  32.                 sprintf(buff,"%d",i);
  33.                 muta_a_EXPR(buff,num2);
  34.                 break;
  35.  
  36.             case -1:/* Se ha producido un error */
  37.                 strcpy(buffer,"Se ha producido un error\n");
  38.                 write(1, buffer, strlen(buffer));
  39.                 break;
  40.             }
  41.         waitpid(pid, &status, 0); //Ejemplo secuencial
  42.     }
  43. }
Add Comment
Please, Sign In to add comment