You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
486 B

4 years ago
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
char *phrase = "My child sent me this!!";
int main()
{
int fd[2], bytesread;
char message[100];
pipe(fd);
if (fork()==0) {
close(fd[0]);
write (fd[1],phrase,strlen(phrase)+1);
close(fd[1]);
} else {
close(fd[1]);
bytesread=read(fd[0],message,100);
printf("Read %d bytes:%s\n", bytesread, message);
close(fd[0]);
}
}