33 lines
761 B
C++
33 lines
761 B
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
|
|
int main() {
|
|
printf("I am Jack...\n");
|
|
if (fork() == 0) {
|
|
int fd1 = open("fa", O_RDONLY);
|
|
char buf[100];
|
|
while (1) {
|
|
memset(buf, 0, 100);
|
|
if (read(fd1, buf, 100) == 0) {
|
|
kill(getppid(), 9);
|
|
return 0;
|
|
}
|
|
printf("\rPeter says:%s", buf);
|
|
fflush(stdout);
|
|
}
|
|
} else {
|
|
int fd2 = open("fb", O_WRONLY);
|
|
char buf[100];
|
|
while (1) {
|
|
fgets(buf, sizeof(buf), stdin);
|
|
write(fd2, buf, sizeof(buf));
|
|
}
|
|
}
|
|
return 0;
|
|
} |