Single Server FIFO C Prog
Single Server FIFO C Prog
#include <stdio.h>
/* =========================== */
double GetArrival(FILE *fp) /* read an arrival time */
/* =========================== */
{
double a;
/* =========================== */
double GetService(FILE *fp) /* read a service time */
/* =========================== */
{
double s;
/* ============== */
int main(void)
/* ============== */
{
FILE *fp; /* input data file */
long index = 0; /* job index */
double arrival = START; /* arrival time */
double delay; /* delay in queue */
double service; /* service time */
double wait; /* delay + service */
double departure = START; /* departure time */
struct { /* sum of ... */
double delay; /* delay times */
double wait; /* wait times */
double service; /* service times */
double interarrival; /* interarrival times */
} sum = {0.0, 0.0, 0.0};
fp = fopen(FILENAME, "r");
if (fp == NULL) {
fprintf(stderr, "Cannot open input file %s\n", FILENAME);
return (1);
}
while (!feof(fp)) {
index++;
arrival = GetArrival(fp);
if (arrival < departure)
delay = departure - arrival; /* delay in queue */
else
delay = 0.0; /* no delay */
service = GetService(fp);
wait = delay + service;
departure = arrival + wait; /* time of departure */
sum.delay += delay;
sum.wait += wait;
sum.service += service;
}
sum.interarrival = arrival - START;
fclose(fp);
return (0);
}