About
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
clook
requests = [176, 79, 34, 60, 92, 11, 41, 114]
head = 50
start = 0
end = 199
direction = 'right'
def clook(requests, head, direction):
requests.append(head)
requests.sort()
total_seek_time = 0
path = []
head_index = requests.index(head)
if direction == 'left':
for i in range(head_index, -1, -1):
path.append(requests[i])
head = requests[i]
head = requests[head_index]
path.append(start)
head = start
for i in range(head_index + 1, len(requests)):
path.append(requests[i])
head = requests[i]
elif direction == 'right':
for i in range(head_index, len(requests)):
path.append(requests[i])
head = requests[i]
head = requests[head_index]
path.append(end)
head = end
for i in range(head_index - 1, -1, -1):
path.append(requests[i])
head = requests[i]
total_seek_time = sum([abs(path[i] - path[i+1]) for i in range(len(path) - 1)])
return total_seek_time, path
def analyze_scan():
print("CLOOK")
print("Requests: ", requests)
print("Head: ", head)
response = clook(requests, head, direction)
print("Path: ", ' -> '.join([str(x) for x in response[1]]))
print("Total Seek Time: ", response[0])
analyze_scan()
cscan
requests = [98, 183, 37, 122, 14, 124, 65, 67]
head = 53
start = 0
end = 199
direction = 'right'
def cscan(requests, head, start, end, direction):
requests.append(head)
requests.sort()
total_seek_time = 0
path = []
head_index = requests.index(head)
if direction == 'left':
for i in range(head_index, start-1, -1):
path.append(requests[i])
head = requests[i]
path.append(start)
head = start
path.append(end)
head = end
for i in range(len(requests) - 1, head_index, -1):
path.append(requests[i])
head = requests[i]
elif direction == 'right':
for i in range(head_index, len(requests)):
path.append(requests[i])
head = requests[i]
path.append(end)
head = end
path.append(start)
for i in range(0, head_index):
path.append(requests[i])
head = requests[i]
head = start
total_seek_time = sum([abs(path[i] - path[i+1]) for i in range(len(path) - 1)])
return [total_seek_time, path]
def analyze_cscan():
print("CSCAN")
print("Requests: ", requests)
print("Head: ", head)
response = cscan(requests, head, start, end, direction)
print("Path: ", ' -> '.join([str(x) for x in response[1]]))
print("Total Seek Time: ", response[0])
analyze_cscan()
fcfs
requests = [98, 183, 37, 122, 14, 124, 65, 67]
head = 53
def fcfs(requests, head):
head_original = head
total_seek_time = 0
path = []
for request in requests:
path.append(request)
head = request
path.insert(0, head_original)
total_seek_time = sum([abs(path[i] - path[i+1]) for i in range(len(path) - 1)])
return total_seek_time, path
def analyze_fcfs():
print("FCFS")
print("Requests: ", requests)
print("Head: ", head)
response = fcfs(requests, head)
print("Path: ", ' -> '.join([str(x) for x in response[1]]))
print("Total Seek Time: ", response[0])
analyze_fcfs()
look
requests = [176, 79, 34, 60, 92, 11, 41, 114]
head = 50
direction = 'right'
def look(requests, head, direction):
requests.append(head)
requests.sort()
total_seek_time = 0
path = []
head_index = requests.index(head)
if direction == 'left':
for i in range(head_index, -1, -1):
path.append(requests[i])
head = requests[i]
head = requests[head_index]
for i in range(head_index + 1, len(requests)):
path.append(requests[i])
head = requests[i]
elif direction == 'right':
for i in range(head_index, len(requests)):
path.append(requests[i])
head = requests[i]
head = requests[head_index]
for i in range(head_index - 1, -1, -1):
path.append(requests[i])
head = requests[i]
total_seek_time = sum([abs(path[i] - path[i+1]) for i in range(len(path) - 1)])
return total_seek_time, path
def analyze_scan():
print("LOOK")
print("Requests: ", requests)
print("Head: ", head)
response = look(requests, head, direction)
print("Path: ", ' -> '.join([str(x) for x in response[1]]))
print("Total Seek Time: ", response[0])
analyze_scan()
scan
requests = [98, 183, 37, 122, 14, 124, 65, 67]
head = 53
start = 0
end = 199
def scan(requests, head, start, end):
requests.append(head)
requests.sort()
total_seek_time = 0
path = []
head_index = requests.index(head)
if head_index < len(requests) - head_index: # left side is fastest
for i in range(head_index, start-1, -1):
path.append(requests[i])
head = requests[i]
path.append(start)
head = start
for i in range(head_index + 1, len(requests)):
path.append(requests[i])
head = requests[i]
else: # right side is fastest
for i in range(head_index, len(requests)):
path.append(requests[i])
head = requests[i]
path.append(end)
head = end
for i in range(head_index - 1, -1, -1):
path.append(requests[i])
head = requests[i]
total_seek_time = sum([abs(path[i] - path[i+1]) for i in range(len(path) - 1)])
return [total_seek_time, path]
def analyze_scan():
print("SCAN")
print("Requests: ", requests)
print("Head: ", head)
response = scan(requests, head, start, end)
print("Path: ", ' -> '.join([str(x) for x in response[1]]))
print("Total Seek Time: ", response[0])
analyze_scan()
sstf
Shortest Seek Time First (SSTF) Disk Scheduling Algorithm
request_list = [98, 183, 37, 122, 14, 124, 65, 67]
head = 53
start = 0
end = 199
def sstf(request_list, head, start):
requests = request_list.copy()
head_original = head
total_seek_time = 0
path = []
while len(requests) > 0:
shortest = abs(head - start)
shortest_index = start
for i in range(len(requests)):
if abs(head - requests[i]) < shortest:
shortest = abs(head - requests[i])
shortest_index = i
path.append(requests[shortest_index])
head = requests[shortest_index]
requests.pop(shortest_index)
path.insert(0, head_original)
total_seek_time = sum([abs(path[i] - path[i+1]) for i in range(len(path) - 1)])
return [total_seek_time, path]
def analyze_sstf():
response = sstf(request_list, head, start)
print("SSTF")
print("Requests: ", request_list)
print("Head: ", head)
print("Path: ", ' -> '.join([str(x) for x in response[1]]))
print("Total Seek Time: ", response[0])
analyze_sstf()
def fifo_page_replacement(pages, capacity):
page_faults = 0
page_frames = []
page_set = set()
for page in pages:
if page not in page_set:
page_faults += 1
if len(page_frames) == capacity:
page_to_remove = page_frames.pop(0)
page_set.remove(page_to_remove)
page_frames.append(page)
page_set.add(page)
return page_faults
def lifo_page_replacement(pages, capacity):
page_faults = 0
page_frames = []
page_set = set()
for page in pages:
if page not in page_set:
page_faults += 1
if len(page_frames) == capacity:
page_to_remove = page_frames.pop()
page_set.remove(page_to_remove)
page_frames.append(page)
page_set.add(page)
return page_faults
def lru_page_replacement(pages, capacity):
page_faults = 0
page_frames = []
page_set = set()
for page in pages:
if page not in page_set:
page_faults += 1
if len(page_frames) == capacity:
page_to_remove = page_frames.pop(0)
page_set.remove(page_to_remove)
page_frames.append(page)
page_set.add(page)
else:
page_frames.remove(page)
page_frames.append(page)
return page_faults
def optimal_page_replacement(pages, capacity):
page_faults = 0
page_frames = []
for page in pages:
if page not in page_frames:
page_faults += 1
if len(page_frames) == capacity:
# Find the page to be replaced
farthest = -1
farthest_index = -1
for i in range(len(page_frames)):
if page_frames[i] not in pages[pages.index(page):]:
farthest_index = i
break
elif pages.index(page_frames[i]) > farthest:
farthest = pages.index(page_frames[i])
farthest_index = i
page_frames[farthest_index] = page
else:
page_frames.append(page)
return page_faults
pages = [7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2]
capacity = 4
fifo_faults = fifo_page_replacement(pages, capacity)
lifo_faults = lifo_page_replacement(pages, capacity)
lru_faults = lru_page_replacement(pages, capacity)
optimal_faults = optimal_page_replacement(pages, capacity)
print("FIFO Page Faults:", fifo_faults)
print("LIFO Page Faults:", lifo_faults)
print("LRU Page Faults:", lru_faults)
print("Optimal Page Faults:", optimal_faults)
class Process:
def _init_(self, pid, allocation, max_request):
self.pid = pid
self.allocation = allocation
self.max_request = max_request
self.need = [max_request[i] - allocation[i] for i in range(len(allocation))]
def _str_(self):
return f'{self.pid}\t{self.allocation}\t{self.max_request}\t{self.need}'
def bankers_algorithm(process_list, total_resources):
total_allocation = [0 for i in range(len(total_resources))]
for process in process_list:
for i in range(len(total_resources)):
total_allocation[i] += process.allocation[i]
total_available = [total_resources[i] - total_allocation[i] for i in range(len(total_resources))]
print(f"Total available: {total_available}")
print(f"Total allocation: {total_allocation}")
print(f"Total resources: {total_resources}")
safe_sequence = []
while len(safe_sequence) < len(process_list):
flag = False
for process in process_list:
if process not in safe_sequence:
if all([process.need[i] <= total_available[i] for i in range(len(total_available))]):
safe_sequence.append(process)
for i in range(len(total_available)):
total_available[i] += process.allocation[i]
flag = True
break
if not flag:
print("No safe sequence found")
return []
return safe_sequence
n = int(input("Number of resources: "))
p = int(input("Number of processes: "))
process_list = []
for i in range(p):
pid = input(f"Process {i} id: ")
allocation = [int(x) for x in input(f"Process {i} allocation: ").split()]
max_request = [int(x) for x in input(f"Process {i} max request: ").split()]
process_list.append(Process(pid, allocation, max_request))
avail_or_total = input("1. Available\n2. Total\n")
if avail_or_total == '1':
total_resources = [int(x) for x in input("Available resources: ").split()]
for p in process_list:
for i in range(len(total_resources)):
total_resources[i] += p.allocation[i]
elif avail_or_total == '2':
total_resources = [int(x) for x in input("Total resources: ").split()]
safe_sequence = bankers_algorithm(process_list, total_resources)
print(f"Safe sequence: {(' -> '.join([str(process.pid) for process in safe_sequence]))}")
[11:12, 07/07/2023] Jaswanth: As of my knowledge cutoff in September 2021, Fuchsia OS is still under active development, and a comprehensive comparison of its features and advantages over other operating systems may not be available. However, I can provide an overview of some aspects that make Fuchsia OS unique and potentially advantageous:
New Microkernel Architecture: Fuchsia OS is built on the Zircon microkernel, which offers advantages such as better modularity, scalability, and isolation. Microkernel architectures tend to provide improved security and stability by minimizing the amount of code running in kernel mode, as well as facilitating the development of customized operating system configurations. [11:12, 07/07/2023] Jaswanth: Flutter Framework: Fuchsia OS incorporates the Flutter framework, a popular UI toolkit for building cross-platform applications. Flutter's ability to create visually appealing and performant user interfaces across multiple platforms, including Fuchsia, Android, iOS, web, and desktop, offers developers a flexible and consistent development experience.