Simulation of distributed system with lamport clock to determine the order of events among multiple processes. Identifies logical order of events with timestamps, deadlocks and stuck processes using wait-for graphs to track dependencies between processes.
(Version: g++.exe (MinGW.org GCC-6.3.0-1) 6.3.0)
- Compile the code with the command: g++ -o tut6 lamport.cpp
- Run the compiled program: ./tut6
Input format: write all the commands on newline, end command accepts any format starting with end (end process, end process p1, end ), an input of newline (enter button twice) will print the output.
begin process p1
print e11
send (p2) e12
print e13
print e14
send (p2) e15
print e16
recv p2 e17
end process
begin process p2
print e21
print e22
recv p1 e12
send (p1) e17
recv p1 e15
print e26
end process
2
begin process p1
recv p2 m2
send (p4) m4
end process
begin process p2
recv p3 m3
send (p1) m2
end
begin process p3
recv p4 m1
send (p2) m3
end process
begin process p4
send (p3) m1
end process
3
begin process p1
recv p2 m2
send (p4) m4
end process
begin process p2
recv p3 m3
send (p1) m2
end
begin process p3
recv p4 m1
send (p2) m3
end process
begin process p4
send (p3) m9
end
4
begin process p1
recv p2 m2
send (p4) m4
end process
begin process p2
recv p3 m3
send (p1) m2
end
begin process p3
recv p4 m1
send (p2) m3
end process
begin process p4
print def
end process
5
begin process p1
recv p2 m2
end process
begin process p2
recv p1 m1
end process
6
begin process p1
recv p2 m2
send (p4) m4
end process
begin process p2
recv p3 m3
send (p1) m2
end
begin process p3
recv p4 m1
send (p2) m3
end process
begin process p4
recv p1 m4
end process
7
begin process p1
send (p2) m1
print abc
print def
end process
begin process p2
print x1
recv p1 m1
print x2
send (p1) m2
print x3
end process
8
begin process p1
send (p2,p3) m1
end process
begin process p2
recv p1 m1
end process
begin process p3
recv p1 m1
end process
9
begin process p1
send (p2) m1
send (p2) m1
end process
begin process p2
recv p1 m1
recv p1 m1
end process
10
begin process p1
send (p2) m1
end process
begin process p2
recv p1 m1
recv p1 m1
end process
- Receiver process does not exist.
- System deadlock
- System stuck (message needed to proceed not sent and deadlock is not there)
- Sender process does not exist
- Incorrect input format
- Starting new process before ending previous
- Starting the same process again
- Empty receivers, message
- Sending msg to itself
- Incorrect command etc.