pingpong finished

This commit is contained in:
2025-02-25 22:25:11 +08:00
parent 5bb955df94
commit b5dcfc539f
8 changed files with 325 additions and 1110 deletions

21
user/pingpong.c Normal file
View File

@ -0,0 +1,21 @@
#include "kernel/types.h"
#include "user/user.h"
int main(int argc, char *argv[]) {
int proc_f2s[2], proc_s2f[2];
char buffer[8];
pipe(proc_f2s);
pipe(proc_s2f);
if (fork() == 0) {
read(proc_s2f[0], buffer, 4);
printf("%d: received %s\n", getpid(), buffer);
write(proc_f2s[1], "pong", strlen("pong"));
} else {
write(proc_s2f[1], "ping", strlen("ping"));
read(proc_f2s[0], buffer, 4);
printf("%d: received %s\n", getpid(), buffer);
}
exit(0);
}