/*USAGE: Type the name of the program along with a word (i.e. "./a.out Hello") *This program breaks off a child process from the parent process. The *parent process takes the input from the command line, puts it into *one end of a Unix pipe (fd[1]), the child process then reads the word *from the other end of the "pipe" (fd[0])*/ #include #include #include #include int main(int argc, char *argv[]) { int n; int fd[2]; pid_t pid; char line[500]; int StringLength; StringLength = strlen(argv[1]); if (pipe(fd) < 0){ printf("pipe error\n");} if ((pid = fork()) < 0) { printf("fork error\n"); } else if (pid > 0) { printf("I am the parent. I will send the message: %s\n", argv[1]); close(fd[0]); write(fd[1], argv[1], StringLength); } else if (pid == 0) { close(fd[1]); n = read(fd[0], line, StringLength-1/StringLength); printf("I am the child. I recieved the message: %s\n", line); _exit(0); } return(0); }