Website/App design एवं college projects आदि के लिए संपर्क करें – 8085589371

Introduction to FCFS

FCFS CPU Scheduling एक प्रकार की सबसे सरल CPU Scheduling है जिसमे जो Process पहले आएगी वही Execute होगी।

  • ये CPU Scheduling Queue की भाती कार्य करती है (जो पहले Process execute होने के लिए आयी है वही Execute होगी)
  • इस प्रकार की Scheduling  में एक बार जो Process execute होना शुरू हो जाने से Complete होने तक चलती रहती है।
  • इस algorithm को ऐसे implement किया जा सकता है FIFO quaue की मदद से।

Key Terms

  • Arrival Time (AT): वह टाइम जब process एंटर होती है ready queue में।
  • Burst Time (BT): Process Execution complete होने में लगा समय।
  • Completion Time (CT): वह समय जिस जी जब process execution complete हुई।
  • Turnaround Time (TAT): CT – AT (process आने के से complete होने तक का समय).
  • Waiting Time (WT): TAT – BT (process execute होने के लिए किया गया wait).

Example:

Process Arrival Time Burst Time
P1 0 5
P2 1 3
P3 2 8
P4 3 6

Gantt Chart –

| P1 | P2 | P3 | P4 |
0 5 8 16 22

Execution Order:

P1 → P2 → P3 → P4 (based on arrival)

Advantages of FCFS

  • Implement करने एवं समझने में आसान।

Disadvantages of FCFS

  • कर के समय और स्तिथि के लिए उपयुक्त नहीं।

Real-Life Example

जहा पर भी लाइन में खड़े होने होते है एक के बाद एक वह FCFS होता है, उदाहरण के लिए मन लेते है की किसी बैंक में गए और वह पर एक लम्बी लाइन में खड़ा होने पड़ा , अब चाहे हमारा काम छोटा हो हो बड़ा वेट तो करना पड़ेगा, और काम एक के बाद ही दूसरा होगा।

FCFS Implementation in C

#include 

struct Process {
    int pid;
    int arrivalTime;
    int burstTime;
    int completionTime;
    int turnaroundTime;
    int waitingTime;
};

int main() {
    int n;
    printf("Enter the number of processes: ");
    scanf("%d", &n);

    struct Process p[n];

    // Input process details
    for(int i = 0; i < n; i++) {
        p[i].pid = i + 1;
        printf("Enter arrival time of P%d: ", p[i].pid);
        scanf("%d", &p[i].arrivalTime);
        printf("Enter burst time of P%d: ", p[i].pid);
        scanf("%d", &p[i].burstTime);
    }

    // Sort processes by arrival time
    for(int i = 0; i < n - 1; i++) {
        for(int j = i + 1; j < n; j++) { if(p[i].arrivalTime > p[j].arrivalTime) {
                struct Process temp = p[i];
                p[i] = p[j];
                p[j] = temp;
            }
        }
    }

    // Calculate Completion, Turnaround and Waiting Time
    int currentTime = 0;
    for(int i = 0; i < n; i++) {
        if(currentTime < p[i].arrivalTime)
            currentTime = p[i].arrivalTime;
        p[i].completionTime = currentTime + p[i].burstTime;
        p[i].turnaroundTime = p[i].completionTime - p[i].arrivalTime;
        p[i].waitingTime = p[i].turnaroundTime - p[i].burstTime;
        currentTime = p[i].completionTime;
    }

    // Print results
    printf("\nPID\tAT\tBT\tCT\tTAT\tWT\n");
    for(int i = 0; i < n; i++) {
        printf("P%d\t%d\t%d\t%d\t%d\t%d\n",
               p[i].pid,
               p[i].arrivalTime,
               p[i].burstTime,
               p[i].completionTime,
               p[i].turnaroundTime,
               p[i].waitingTime);
    }

    return 0;
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top