Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void error_y_exit(char *msg, int exit_status)
- {
- perror(msg);
- exit(exit_status);
- }
- void muta_a_EXPR(char *num1, char *num2)
- {
- execlp("expr",num1,"*",num2,(char *) NULL);
- error_y_exit("Ha fallado la mutacion al expr",1);
- }
- int main(int argc,char *argv[])
- {
- char *buff;
- char buffer[80];
- int pid;
- int i;
- int status;
- char *num2 = argv[1];
- for (i = 1; i <= 10;i++)
- {
- pid=fork();
- switch (pid) {
- case 0: /* Escribe aqui el codigo del proceso hijo */
- sprintf(buff,"%d",i);
- muta_a_EXPR(buff,num2);
- break;
- case -1:/* Se ha producido un error */
- strcpy(buffer,"Se ha producido un error\n");
- write(1, buffer, strlen(buffer));
- break;
- }
- waitpid(pid, &status, 0); //Ejemplo secuencial
- }
- }
Add Comment
Please, Sign In to add comment