#!/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[@]}

# Initialize waiting time and turnaround time arrays
waiting_time=()
turnaround_time=()

# Initialize total waiting time and turnaround time variables
total_waiting_time=0
total_turnaround_time=0

# Calculate waiting time and turnaround time for each process
for ((i=0; i<num_processes; i++)); do
    if [ $i -eq 0 ]; then
        waiting_time[$i]=0
    else
        waiting_time[$i]=$((waiting_time[$i-1] + burst_times[$i-1]))
    fi
    turnaround_time[$i]=$((waiting_time[$i] + burst_times[$i]))
    total_waiting_time=$((total_waiting_time + waiting_time[$i]))
    total_turnaround_time=$((total_turnaround_time + turnaround_time[$i]))
done

# Calculate average waiting time and average turnaround time
average_waiting_time=$(bc <<< "scale=2; $total_waiting_time / $num_processes")
average_turnaround_time=$(bc <<< "scale=2; $total_turnaround_time / $num_processes")

# Print the results
echo "FCFS Scheduling Algorithm Simulation"
echo "-----------------------------------"
echo "Process  Burst Time  Waiting Time  Turnaround Time"
for ((i=0; i<num_processes; i++)); do
    echo "${processes[$i]}        ${burst_times[$i]}           ${waiting_time[$i]}             ${turnaround_time[$i]}"
done
echo "-----------------------------------"
echo "Average Waiting Time: $average_waiting_time"
echo "Average Turnaround Time: $average_turnaround_time"

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: