SHARE
TWEET

Untitled

a guest Dec 16th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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_PS(char *num1, char *num2)
  13. {
  14.    execlp("expr", "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 *n1;
  27.     n1 = argv[1];
  28.     for (i = 1; i <= 10;i++)
  29.     {
  30.         pid=fork();
  31.         switch (pid) {
  32.             case 0: /* Escribe aqui el codigo del proceso hijo */
  33.                 sprintf(buff,"%d",i);
  34.                 muta_a_PS(n1,buff);
  35.                 break;
  36.  
  37.             case -1:/* Se ha producido un error */
  38.                 strcpy(buffer,"Se ha producido un error\n");
  39.                 write(1, buffer, strlen(buffer));
  40.                 break;
  41.             }
  42.         waitpid(pid, &status, 0); //Ejemplo secuencial
  43.     }  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top