please i need corect answear Implement Lamport’s logical clocks with three process p1, p2, p3 where each clock duration at 3, 5, and 6 respectively

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please i need corect answear

Implement Lamport’s logical clocks with three process p1, p2, p3 where each clock duration at 3, 5, and 6 respectively

 
Expert Solution
Step 1
For master clock serve
 
#Python3 program imitating a clock server
 
from functools import reduce from dateutil import parser.
 
import threading import datetime
 
import socket
 
import time
 
# datastructure used to store client address and clock data client data ()
 
M nested thread function used to receive clock time fron a connected client
 
def startRecieveingClockTime(connector, address):
 
while True: # recieve clock time
 
clock_time_string = connector.recv(1024).decode() clock_time = parser.parse(clock_time_string) clock time diff datetime.datetime.now() -
 
clock_time
 
client_data[address] (
 
"clock_time"
 
:clock_time, "time difference" clock time diff..
 
"connector
 
: connector
 
print("Client Data updated with: + str(address),
 
end "\n\n")
 
time.sleep(5)
 
master thread function used to open portal for accepting clients over given port def startConnecting(master_server):
 
#fetch clock time at slaves / clients while True:
 
# accepting a client / slave clock client master slave connector, addr master server.accept() slave address = str(addr[0])+" + str(addr[1])
 
print(slave_address" got connected successfully")
 
current thread threading. Thread(
 
target startRecieveingClockTime, args = (master slave_connector,
 
slave address, ))
 
current_thread.start()
 
#subroutine function used to fetch average clock difference def getAverageClockDiff():
 
current client data = client_data.copy()
 
time_difference_list = list(client'time_difference"]
 
for client_addr, client in client data.items())
 
sum_of_clock_difference = sum(time difference list,
 
datetime, timedelta(0, 0))
 
average_clock_difference = sum_of_clock_difference \
 
/ len(client_data)
 
return average_clock_difference
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Embedded software development
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education