-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPong.java
More file actions
35 lines (21 loc) · 1.03 KB
/
Pong.java
File metadata and controls
35 lines (21 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class Pong extends UserLandProcess{
public void main() {
int pingPID = OS.searchPID("Ping").get();
int pongPID = OS.getPID();
System.out.println("PONG: My name is PONG and my pid is: " + pongPID);
System.out.println("PONG: Ping's PID is: " + pingPID);
System.out.println("PONG: Sending message.");
OS.sendMessage(new Message(pongPID, pingPID, 0, new byte[]{80, 111, 110, 103}));
cooperate();
while(true){
System.out.println("PONG: Waiting for message.");
Message pingMessage = OS.waitForMessage();
System.out.println("PONG: Ping sent \"" + new String(pingMessage.getData()) + "\" From PID: " + pingMessage.getSender() + " Signal: " + pingMessage.getSignal());
cooperate();
System.out.println("PONG: Sending message.");
OS.sendMessage(new Message(pongPID, pingPID, pingMessage.getSignal()+1, new byte[]{80, 111, 110, 103}));
OS.sleep(200);
cooperate();
}
}
}