-- pipe.c -- #include #include #include #include #include int main(void) { int fd[2], nbytes; pid_t childpid; char string[] = "Hello, world!\n"; char readbuffer[80]; pipe(fd); if ((childpid = fork()) == -1) { perror("fork"); exit(1); } if (childpid == 0) { /* Child process closes up input side of pipe */ close(fd[0]); /* Send "string" through the output side of pipe */ while (scanf("%s", readbuffer) != EOF) write(fd[1], readbuffer, (strlen(readbuffer) + 1)); exit(0); } else { /* Parent process closes up output side of pipe */ close(fd[1]); /* Read in a string from the pipe */ while (nbytes = read(fd[0], readbuffer, sizeof(readbuffer))) printf("Received %d bytes: %s\n", nbytes, readbuffer); } return (0); } -- pthread.c -- -- compile with the -lpthread flag -- #include #include #include #include char buf[1024]; int p = 0; void printer(){ while (1){ sleep(1); printf("\nBuffer: %s\n", buf); p = 0; memset(buf, '\0', sizeof(buf)); } } int main(){ pthread_t prnt; char x; buf[0]='\0'; pthread_create(&prnt, NULL, (void *)(printer), NULL); while ((x = getchar()) != EOF) buf[p++] = x; return 0; }