B

@bull_123

reader writer

Bash
2 years ago
#!/bin/bash #!/bin/bash # Initialize the semaphore and shared variable declare -i readers_count=0 declare -i resource=0 # Semaphore for readers declare -i mutex_readers=1 declare -i mutex_writers=1

banking algorithm

Bash
2 years ago
#!/bin/bash #!/bin/bash # Number of processes and resources num_processes=5 num_resources=3 # Available resources available=(10 5 7)

Priority scheduling algorithm

Bash
2 years ago
#!/bin/bash # Define an array to store process names processes=("P1" "P2" "P3" "P4") # Define an array to store burst times for each process burst_times=(8 4 9 5) # Define an array to store priority values for each process priorities=(3 1 4 2)

LJF

Bash
2 years ago
#!/bin/bash # Define an array to store process names processes=("P1" "P2" "P3" "P4") # Define an array to store burst times for each process burst_times=(5 3 8 2) # Calculate the number of processes

Round Robin

Bash
2 years ago
#!/bin/bash # Define an array to store process names processes=("P1" "P2" "P3" "P4") # Define an array to store burst times for each process burst_times=(8 4 9 5) # Define the time quantum (time slice)

SJF

Bash
2 years ago
#!/bin/bash # Define an array to store process names processes=("P1" "P2" "P3" "P4") # Define an array to store burst times for each process burst_times=(5 3 8 2) # Calculate the number of processes num_processes=${#processes[@]}

FCFS

Bash
2 years ago
#!/bin/bash # Define an array to store process names processes=("P1" "P2" "P3" "P4") # Define an array to store burst times for each process burst_times=(5 3 8 2) # Calculate the number of processes num_processes=${#processes[@]}

sum

Bash
2 years ago
#!/bin/bash # Prompt the user to enter the value of n read -p "Enter the value of n: " n sum=0 counter=1 # Calculate the sum using a while loop while [ $counter -le $n ] do

factorial

Bash
2 years ago
#!/bin/bash # Prompt the user to enter a number read -p "Enter a number: " number factorial=1 # Calculate the factorial using a for loop for (( i=1; i<=number; i++ )) do factorial=$((factorial * i))

palindrome number

Bash
2 years ago
#!/bin/bash # Prompt the user to enter a number read -p "Enter a number: " number # Reverse the number reverse="" temp=$number while [ $temp -gt 0 ] do remainder=$((temp % 10))

first and last string

Bash
2 years ago
#!/bin/bash # Prompt the user to enter a string read -p "Enter a string: " input_string # Extract the first character first_character="${input_string:0:1}" # Extract the last character last_character="${input_string: -1}"

strings are equal or not

Bash
2 years ago
#!/bin/bash # Prompt the user to enter the first string read -p "Enter the first string: " string1 # Prompt the user to enter the second string read -p "Enter the second string: " string2 # Compare the two strings if [ "$string1" == "$string2" ]; then echo "The strings are equal."