Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <signal.h>
- #include <fcntl.h>
- #include <sys/wait.h>
- #include <errno.h>
- int main(int argc, char *argv[]){
- int pid, fd[2], estado;
- int buf[256];
- creat(argv[2], 7777);
- //printf("%dn", f);
- pipe(fd);
- int nhijos = *argv[1] -'0';
- for(int i=0; i<nhijos; i++){
- switch(fork()){
- case 0: //Hijo
- close (fd[0]);
- close (1);
- dup(fd[1]);
- close(fd[1]);
- pid = getpid();
- buf[1]= pid;
- write(1, buf, 2);
- write(1, "n", 1);
- exit(0);
- case -1:
- printf("fork");
- default: //Padre
- close (fd[1]);
- close (0);
- dup(fd[0]);
- close(fd[0]);
- read(0, buf, 3);
- write(3, buf, 3);
- int err;
- err = wait(&estado);
- }
- }
- printf("Termino la ejecucion n");
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement