Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char *argv[])
- {
- int fd[2];
- pid_t pid;
- char buf;
- pipe( fd );
- pid = fork();
- switch( fork() ){
- case -1:
- perror( "fork()" );
- exit( 1 );
- case 0:
- close(fd[0]);
- while (read(0, &buf, 1) > 0) {
- write(fd[1], &buf, 1);
- }
- write(1, "Death childn", 12);
- close(fd[1]);
- break;
- default:
- close(fd[1]);
- while (read(fd[0], &buf, 1) > 0) {
- write(1, &buf, 1);
- }
- write(1, "Death parentn", 12);
- close(fd[0]);
- wait(NULL);
- break;
- }
- }
- while (read(0, &buf, 1) > 0) {
- write(fd[1], &buf, 1);
- }
- while (read(fd[0], &buf, 1) > 0) {
- write(1, &buf, 1);
- }
Add Comment
Please, Sign In to add comment