Write a program that can simulate the following CPU scheduling algorithms:

1. FCFS
2. RR (new processes are added at the beginning of the ready queue, the quantum is one time unit)
3. Priority based
4. SJF non-preemptive
5. SRTF

The program can be written in either C or Pascal. Although the platform for development can be one of your choice, the program must be portable (i.e. platform independent) and its final version must run correctly on the server of the computer science department where the grading will be performed.

Specifications:

1. The program must:

1. Ask the user for the name of a file containing its input data. The file will have the following format:
0. Number of processes.
1. A number of lines containing the data for each process. Each process will have one line which will contain in the following order: the burst time, the priority (the lower the number the higher the priority) and the arrival time.
2. The algorithm(s) required. The algorithm will be specified as one of: FCFS, RR, Priority, SJF, SRTF

This is an example of an input file (corresponding to exercise 5.3 page 150):

5

10 3 0

1 1 0

2 3 0

1 4 0

5 2 0

FCFS

SJF

Priority

RR
2. Calculate the Gantt diagram. The diagram will be displayed as follows:

0 -p1- 2 -p2- 5 -p3- 7

The example shows P1 running for 2 time units (from 0 to 2) then P2 running for 3 time units (from 2 to 5) then P3 running for 2 units (from 5 to 7).
3. Calculate the waiting time of each process and the average waiting time for the given algorithms.
my mail: << email address snipped>> plz send in my mail

Dani AI

Generated

Practical, compact plan to implement the schedulers, produce the Gantt diagram, and compute waiting times. pointed to background reading and / correctly criticized the posting style — the grader expects a deterministic program, so make the behaviour explicit and show effort. Below are concrete implementation notes you can apply directly.

Use a single Process struct and an explicit ready queue (deque or circular buffer). Track: pid, burst, remaining, priority, arrival, start (-1), completion. A simple tick-or-event loop is fine; record each run segment (start, end, pid) so you can print and coalesce the Gantt diagram later.

typedef struct {
  int pid;
  int burst;
  int rem;
  int priority;   // lower number = higher priority
  int arrival;
  int start;      // -1 if not started
  int completion; // -1 if not finished
} Process;

Pseudocode (skeleton):

time = 0;
while (some process unfinished) {
  add arrivals at time to ready (insert rule depends on RR spec);
  choose next process according to scheduler;
  delta = scheduling quantum or until preemption/finish;
  record segment (time, pid, time+delta);
  update rem, start/completion, time += delta;
  update ready queue (reinsert, remove, etc.);
}

Scheduler specifics and gotchas:

  • FCFS: FIFO by arrival (tie-break by pid).
  • SJF (non-preemptive): when CPU free pick ready job with smallest burst.
  • SRTF: preempt current if a newly ready process has smaller remaining time.
  • Priority: interpret as non-preemptive unless your assignment says otherwise; lower number = higher priority.
  • RR (quantum = 1): follow the spec that newly arrived processes are inserted at the beginning of the ready queue — define clearly whether arrivals at the same tick go before or after the currently running slice. This insertion rule can cause younger arrivals to repeatedly preempt older jobs; document the tie-break you choose.

Gantt and metrics:

  • Keep segments, merge adjacent segments of same pid, print like: 0 -p1- 2 -p2- 5.
  • Completion = time when rem==0. Turnaround = completion - arrival. Waiting = turnaround - burst. Average = sum(waiting)/n.

Portability checklist: stick to standard C (stdio.h, stdlib.h, string.h), exact output formatting, and deterministic tie-breaks so the grader can reproduce results.

Recommended Answers

All 3 Replies

You don't need to start duplicate threads for same problem. Check this
Scheduling Algorithm

And we're not going to do the homework for lazy kids who can't even be bothered to try and hide that it's homework nor try to come up with a title that's even remotely descriptive.

We WANT such kids to fail so they won't bother us as potential colleagues later.

commented: Works for me :) - Salem +5

An excellent example of how not to post a question, if anyone cares.

> plz help me plz plz plz plz plz plz
Don't sound like an illiterate boob
http://www.catb.org/~esr/faqs/smart-questions.html#writewell

> Write a program that can simulate the following CPU scheduling algorithms:
Don't beg others to do your own homework.
http://www.daniweb.com/techtalkforums/announcement8-2.html
http://www.catb.org/~esr/faqs/smart-questions.html#id273364
http://www.catb.org/~esr/faqs/smart-questions.html#homework

> my mail: plz send in my mail
Great - you're just going round spamming every board and forum in sight, and just hoping some schmuck is going to save your lazy arse?
http://www.catb.org/~esr/faqs/smart-questions.html#noprivate

Do the world a favour and just fail already, so the rest of us can get on with the future, while you work on the "do you want fries with that" speech.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.