Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:08:03+00:00 2026-06-15T13:08:03+00:00

I have been given an assignment to read mock processes from a txt file

  • 0

I have been given an assignment to read mock processes from a txt file that looks like this.

ID: 35; Arrival_Time: 0; Total_Exec_Time: 4;
ID: 65; Arrival_Time: 2; Total_Exec_Time: 6;
ID: 10; Arrival_Time: 3; Total_Exec_Time: 3;
ID: 124; Arrival_Time: 5; Total_Exec_Time: 5;
ID: 182; Arrival_Time: 6; Total_Exec_Time: 2;

I have to complete two algorithms from the choices of (First come first serve, Shortest Proccess Next, Shortest Remaining Time, Round Robin q=2). I need to print out the current time and the process that is running at that time based on whichever two algos I choose. I have successfully completed the FCFS. My next approach is on SRT, except I am having some serious issues with the logic behind the algorithm.

I am currently attempting an iterative approach (posted below) which works to a certain extent (up until current time 9), however I feel it may just be a lucky coincidence.

Does anyone have any suggestions for this algorithm, or one of the other two. I have been on this task for several days now and decided to suck up my pride and post on stack.

Note: This is my first experience with shell scripting, so my code may be a little messy. I am still trying to understand KornShell (ksh).

file="/path/to/file.txt"
  IFS=': \;'
  i=0
  while read -r f1 f2 f3 f4 f5 f6  
    do 
      integer id[i]="$f2" #id array
      integer at[i]="$f4" #arrival time array
      integer et[i]="$f6" #exec time array
      integer rt[i]=0 #run time so far
      integer current[i]=i

      ((i++))
    done <"$file"

  integer curr_index=0
  integer currTime=0
  let totalProcesses=${#at[@]}
  let totalProcesses=totalProcesses-1
  let totalRunTime=0
  for x in ${et[@]}; do
    let totalRunTime+=$x
  done 

  scheduleTask () { 
    currTime=$1
    for y in ${current[@]}; do
      if (( rt[$y] < et[$y] )); then
        #if the program is not finished, keep going
        if (( at[$y] < $currTime )); then
          #if the program is in que, keep going
          let diff=et[$y]-rt[$y]#not currently using
          let currDiff=et[$curr_index]-rt[$curr_index] #not currently using         
          if (( et[$y] <= et[$curr_index] )); then #is this broken?
            curr_index=$y
          fi
        fi
      else
        echo "${id[$y]} RAN ${rt[$y]} out of ${et[$y]} seconds"

        unset current[$y]
      fi
    done
  }

  for (( i = 0; i < $totalRunTime; i++ )); do
    echo "================================="
    scheduleTask $i 
    ((rt[$curr_index]++))
    print "\t\tcurrent time: $i"
    print "\t\t\tcurrent process: ${id[$curr_index]}"
    echo "================================="
  done

The proper output for SRT should read like this..

=================================
        current time: 0
            current process: 35
=================================
=================================
        current time: 1
            current process: 35
=================================
=================================
        current time: 2
            current process: 35
=================================
=================================
        current time: 3
            current process: 35
=================================
=================================
        current time: 4
            current process: 10
=================================
=================================
        current time: 5
            current process: 10
=================================
=================================
        current time: 6
            current process: 10
=================================
=================================
        current time: 7
            current process: 182
=================================
=================================
        current time: 8
            current process: 182
=================================
=================================
        current time: 9
            current process: 124
=================================
=================================
        current time: 10
            current process: 124
=================================
=================================
        current time: 11
            current process: 124
=================================
=================================
        current time: 12
            current process: 124
=================================
=================================
        current time: 13
            current process: 124
=================================
=================================
        current time: 14
            current process: 65
=================================
=================================
        current time: 15
            current process: 65
=================================
=================================
        current time: 16
            current process: 65
=================================
=================================
        current time: 17
            current process: 65
=================================
=================================
        current time: 18
            current process: 65
=================================
=================================
        current time: 19
            current process: 65
=================================
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:08:05+00:00Added an answer on June 15, 2026 at 1:08 pm

    I’m still relatively new to stack overflow and was naive to the thoughts and opinions about homework assignments. I was debating on removing the question, but after reading this post( https://meta.stackexchange.com/questions/10811/how-to-ask-and-answer-homework-questions ), I decided my question fits the guidelines and therefore is worthy of keeping up.

    I figured out the Shortest remaining time algorithm. I am thankful that no one answered this question, figuring out the algorithm on my own (with some help from my TA) was worth it. Therefore, my provided answer will have the basic pseudo logic and no actual code.

    shortest = the first process read from the input(assuming it has already arrived)
    while there are still processes to be run
         process = next process (out of processes that have not completed yet)
         if (process arrival time <= currentTime) #process arrived 
               if (process execution time < shortest execution time)
                     shortest = process
    

    NOTE: This is just about the same help I received from my TA (who wrote the assignment) which is why I feel comfortable posting this answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given an assignment for university where i have to read from
I just been given a new assignment which looks like its going to be
I'm very new to Perl and have been given an assignment that is a
Good day, I have been given an assignment that gets data off a CSV
I have been given the following assignment: Write a function (documentation included) that given
I have been given a question on an assignment that has got me stumped.
I am struggeling with an assignment we have been given. I have written this
I have been given the task of importing an obj file and loading it
I have been given an assignment in which I am supposed to write an
For college, we have been given an assignment where, given an image, we have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.