#include "kernel/types.h" #include "user/user.h" int main(int argc, char** argv) { int p[2]; // hell, read from p[0] and write to p[1] no matter in pa/ch if (pipe(p) == -1) exit(1); uint8 senddata[] = {0xAC}; uint8 recvdata[] = {0}; int pid = fork(); if (pid == 0) { // child if (read(p[0], recvdata, 1) != 1) printf("error child read\n"); close(p[0]); printf("%d: received ping\n", getpid()); if (write(p[1], senddata, 1) != 1) printf("error child write\n"); close(p[1]); exit(0); } else { if (write(p[1], senddata, 1) != 1) printf("error parent write\n"); close(p[1]); if (read(p[0], recvdata, 1) != 1) printf("error parent read\n"); printf("%d: received pong\n", getpid()); close(p[0]); exit(0); } }