• Tushuntirish
  • Operatsion tizimlar” fani bo’yicha mustaqil ish 1 Topshirdi: Bozorov Jamshid Guruh raqami




    Download 489,35 Kb.
    bet3/5
    Sana16.05.2024
    Hajmi489,35 Kb.
    #237094
    1   2   3   4   5
    O'rtacha kutish vaqti:



    Kod:
    C++ da FCFS algoritmini amalga oshirish uchun kod quyida keltirilgan:

    #include


    using namespace std;

    void findWait_Time(int processes[], int size, int burst_time[],


    int wait_t[], int arrival_t[])
    {
    int service_time[size];
    service_time[0] = arrival_t[0];
    wait_t[0] = 0;

    int i = 1;


    // calculating waiting time


    while ( i < size )
    {

    service_time[i] = service_time[i-1] + burst_time[i-1];

    //waiting time = sum - at[i]


    wait_t[i] = service_time[i] - arrival_t[i];

    if (wait_t[i] < 0)


    wait_t[i] = 0;

    i++;
    }


    }
    void findavg_wait_Time(int processes[], int size, int burst_t[], int arrival_t[])
    {
    int wt[size], tat[size];

    findWait_Time(processes, size, burst_t, wt, arrival_t);

    cout << "Processes " << " Burst Time " << " Arrival Time "
    << " Waiting Time \n";
    int total_wt = 0, total_tat = 0;

    int i = 0;


    while (i < size)
    {
    total_wt = total_wt + wt[i];
    total_tat = total_tat + tat[i];
    int compl_time = tat[i] + arrival_t[i];
    cout << " " << i+1 << "\t\t" << burst_t[i] << "\t\t"
    << arrival_t[i] << "\t\t" << wt[i] << "\t\t "
    << endl;

    i++;
    }

    cout << "Average waiting time = "


    << (float)total_wt / (float)size;

    }

    int main()


    {

    int processes[] = {4, 3, 1, 5, 2};


    int n = sizeof processes / sizeof processes[0];

    int arrival_time[] = {0, 1, 2, 4, 5};



    int burst_time[] = {3, 8, 6, 4, 2};
    findavg_wait_Time(processes, n, burst_time, arrival_time);

    return 0;


    }
    FCFS rejalashtirishni amalga oshirish
    Tushuntirish:
    Amalga oshirish tartibi: Dastur barcha jarayonlar uchun birinchi navbatda berilgan portlash va kelish vaqtini ishlatib, kutish vaqtini topadi va u tugagach, oʻrtacha kutish vaqtini (float)total_wt / (float) hajmi boʻyicha hisoblab chiqadi va jarayonlar boʻyicha tafsilotlarni koʻrsatadi.

    23–24-qator: Agar biron-bir jarayon uchun kutish vaqti salbiy bo'lsa, bu u allaqachon navbatda turganligini anglatadi, shuning uchun protsessor ishlamay qolishidan oldin uning kutish vaqti 0, wt[i] = 0 bo'ladi.



    Download 489,35 Kb.
    1   2   3   4   5




    Download 489,35 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Operatsion tizimlar” fani bo’yicha mustaqil ish 1 Topshirdi: Bozorov Jamshid Guruh raqami

    Download 489,35 Kb.