pingpong finished
This commit is contained in:
21
user/pingpong.c
Normal file
21
user/pingpong.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user