spawn implemented.
[mit-jos.git] / user / pingpong.c
blob4dfeedb5250c2d7ddd10dc8b26b082fd8d1fbb83
1 // Ping-pong a counter between two processes.
2 // Only need to start one of these -- splits into two with fork.
4 #include <inc/lib.h>
6 void
7 umain(void)
9 envid_t who;
11 if ((who = fork()) != 0) {
12 // get the ball rolling
13 cprintf("send 0 from %x to %x\n", sys_getenvid(), who);
14 ipc_send(who, 0, 0, 0);
17 while (1) {
18 uint32_t i = ipc_recv(&who, 0, 0);
19 cprintf("%x got %d from %x\n", sys_getenvid(), i, who);
20 if (i == 10)
21 return;
22 i++;
23 ipc_send(who, i, 0, 0);
24 if (i == 10)
25 return;