Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (cid = 0; cid < 2; cid++)
- {
- printf("Filho criado! id = %d n", cid);
- if((pid = fork()) == -1)
- {
- perror("fork");
- exit(1);
- }
- else
- {
- if(pid == 0 && cid == 0)
- {
- /* Child process closes up input side of pipe */
- close(fd[0]);
- /* Send "string" through the output side of pipe */
- write(fd[1], string1, (strlen(string1)+1));
- exit(0);
- }
- else if(pid == 0 && cid == 1)
- {
- /* Child process closes up input side of pipe */
- close(fd[0]);
- /* Send "string" through the output side of pipe */
- write(fd[1], string2, (strlen(string2)+1));
- exit(0);
- }
- else if (pid > 1)
- {
- printf("Eu sou o Papai !n");
- }
- }
- }
- /*wait for childs*/
- while((wpid = wait(&status)) > 0);
- /* Parent process closes up output side of pipe */
- close(fd[1]);
- /* Read in a string from the pipe */
- nbytes = read(fd[0], readbuffer, sizeof(readbuffer));
- printf("Received string: %s", readbuffer);
- return(0);
Add Comment
Please, Sign In to add comment