Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # vOTE
- process = int(input("Enter the number of process: "))
- processes = list(range(0,process))
- processes.remove(int(input("Enter the process which want to go to critical state: ")))
- votes = 0
- print("Enter 1 if you want to vote, else enter 0")
- for i in processes:
- print("Enter your vote process"+str(i)+": ",end='')
- k = int(input())
- if k==1:
- votes+=1
- if votes>=(process-1)//2:
- print("The process can go to critical section")
- else:
- print("The process can't go to critical section")
- #tS
- n = int(input("Enter number of process: \n"))
- timestamp = []
- for i in range(n):
- timestamp.append(input())
- dict = dict(zip(timestamp, list(map(lambda x : int(x[:2]*60) + int(x[3:]), timestamp))))
- print(timestamp.index(sorted(dict)[0]))
- #BERK
- a = int(input("Enter the number of machines: [excluding main machine] "))
- time = []
- main = input("Enter the time in the main system [hh:mm]: ")
- main_time_minutes = int(main[:2]) * 60 + int(main[3:])
- for i in range(a):
- print("Enter the time in the machine", i + 1, "[hh:mm]: ", end="")
- time.append(input())
- for i in range(a):
- machine_time_minutes = int(time[i][:2]) * 60 + int(time[i][3:])
- correction_value = main_time_minutes - machine_time_minutes
- machine_time_minutes += correction_value
- hours = machine_time_minutes // 60
- minutes = machine_time_minutes % 60
- time[i] = f"{hours:02d}:{minutes:02d} [Correction Value: {correction_value:+}]"
- for i in range(a):
- print("Node", i + 1, ": corrected value:", time[i])
- #LAM
- class Process:
- def __init__(self, id):
- self.id = id
- self.clock = 0
- def internal_event(self):
- self.clock += 1
- print(f"Process {self.id} executed internal event. Clock: {self.clock}")
- def send_message(self, other_process):
- self.clock += 1
- print(f"Process {self.id} sends message to Process {other_process.id}. Clock: {self.clock}")
- other_process.receive_message(self)
- def receive_message(self, from_process):
- self.clock = max(self.clock, from_process.clock) + 1
- print(f"Process {self.id} received messsage from Process {from_process.id}. Clock: {self.clock}")
- if __name__ == "__main__":
- p1 = Process(1)
- p2 = Process(2)
- p1.internal_event()
- p2.internal_event()
- p1.send_message(p2)
- p2.send_message(p1)
- import socket
- # Create a socket object
- client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- # Connect to the server using the server IP address and port
- client_socket.connect(("127.0.0.1", 12345))
- # Send a message to the server
- message = input("Enter a message to send to the server: ")
- client_socket.send(message.encode())
- # Receive the encoded message from the server
- encoded_message = client_socket.recv(1024).decode()
- print("Received from server:", encoded_message)
- # Close the client socket
- client_socket.close()
- import socket
- # Create a socket object
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- # Get the local machine name and port
- host = '127.0.0.1'
- port = 12345
- # Bind the socket to a specific address and port
- server_socket.bind((host, port))
- # Listen for incoming connections
- server_socket.listen(1)
- print("Server listening on {}:{}".format(host, port))
- # Accept a client connection
- client_socket, addr = server_socket.accept()
- print("Connection established from:", addr)
- # Receive data from the client
- data = client_socket.recv(1024).decode()
- print("Received from client:", data)
- message = input("Enter msg:")
- # Echo the data back to the client
- client_socket.send(message.encode())
- # Close the client socket
- client_socket.close()
- import socket
- client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- client_socket.connect(('127.0.0.1', 4444))
- file_list_str = client_socket.recv(1024).decode()
- file_list = file_list_str.split("\n") # Corrected the split character
- print("Available files:")
- for file_name in file_list:
- print(file_name)
- client_socket.close()
- import os
- import socket
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server_socket.bind(('127.0.0.1', 4444))
- server_socket.listen()
- print('Server started. Waiting for client connection...')
- client_socket, client_address = server_socket.accept()
- print('Client connected:', client_address)
- file_list = os.listdir()
- file_list_str = "\n".join(file_list)
- client_socket.send(file_list_str.encode())
- client_socket.close()
- server_socket.close()
- import xmlrpc.client
- # Create a client
- client = xmlrpc.client.ServerProxy("http://localhost:8000/")
- # Input date of birth
- date_of_birth = input("Enter your date of birth (YYYY-MM-DD): ")
- # Extract the year from the date_of_birth
- year_of_birth = int(date_of_birth.split("-")[0])
- # Call the remote function on the server with the year of birth
- age = client.calculate_age(year_of_birth)
- # Print the result
- print(f"Your age is: {age} years")
- import xmlrpc.server
- # Create a server
- server = xmlrpc.server.SimpleXMLRPCServer(("localhost", 8000))
- # Function to calculate age
- def calculate_age(year_of_birth):
- current_year = 2023 # You can use the actual current year
- age = current_year - year_of_birth
- return age
- # Register the function
- server.register_function(calculate_age, "calculate_age")
- # Start the server
- print("Server is running on port 8000...")
- server.serve_forever()
- #dead
- class ResourceAllocationGraph:
- def init(self, number_of_nodes):
- self.edges = []
- self.visited = [0] * number_of_nodes
- def add_edge(self, source, destination):
- self.edges.append((source, destination))
- def has_deadlock(self, node):
- if self.visited[node] == 1:
- return True
- if self.visited[node] == 0:
- self.visited[node] = 1
- for edge in self.edges:
- if edge[0] == node and self.has_deadlock(edge[1]):
- return True
- self.visited[node] = 2
- return False
- if name == "main":
- number_of_nodes = 4
- graph = ResourceAllocationGraph(number_of_nodes)
- # Add edges to the resource allocation graph
- graph.add_edge(0, 1)
- graph.add_edge(1, 2)
- graph.add_edge(2, 0)
- graph.add_edge(2, 3)
- if any(graph.has_deadlock(node) for node in range(number_of_nodes)):
- print("Deadlock detected.")
- else:
- print("No deadlock detected.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement