C Program for FCFS CPU scheduling algorithm

Saturday, September 19th, 2009

OUTPUT:
enter no of processes: 5

enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1

p_name  P_time  w_time
aaa    4    0
bbb    3    4
ccc    2    7
ddd    5    9
eee    1    14
total waiting time=34
avg waiting time=6.80

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
char p[10][5];
int tot=0,wt[10],i,n;
float avg=0;
clrscr();
printf("enter no of processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
 
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}

OUTPUT:
enter no of processes: 5

enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1

p_name  P_time  w_time
aaa    4    0
bbb    3    4
ccc    2    7
ddd    5    9
eee    1    14
total waiting time=34
avg waiting time=6.80

Author Name :
Ranjith

Total : 83 Comments


83 Responses to “C Program for FCFS CPU scheduling algorithm”

  1. nidhya says:

    hi friends i dont know large programs pls give some examples to my mail its a humble request

  2. komal says:

    hii… i want only algo for fcfs plzzz help …..

  3. Anonymous says:

    import java.lang.*;
    import java.util.*;
    class cgpa
    {
    public static void main(String args[])
    {
    int i;
    float d,e,f;
    float[] c=new float[50];
    float[] b=new float[50];
    float[] a=new float[50];
    Scanner sc=new Scanner(System.in);
    System.out.println(“Enter number of grade points obtained by the student in 1st semester”);
    System.out.println(“Enter number of grade points obtained by the student in English and C”);
    for(i=1;i<3;i++)
    {
    c[i]=sc.nextInt();
    c[i]=(c[i]*3);
    c[i]=c[i]+c[i-1];
    }
    System.out.println("Enter number of grade points obtained in Maths-1,Physics-1,Chemistry-1");
    for(i=1;i<4;i++)
    {
    b[i]=sc.nextInt();
    b[i]=(b[i]*4);
    b[i]=b[i]+b[i-1];
    }
    System.out.println("Enter number of grade points obtained in C lab,Chemistry lab,Workshop");
    for(i=1;i<4;i++)
    {
    a[i]=sc.nextInt();
    a[i]=(a[i]*2);
    a[i]=a[i]+a[i-1];
    }
    d=(a[3]+b[3]+c[2])/24;
    System.out.println("SGPA Of the 1st semester is"+(float)d);
    System.out.println("Enter number of grade points obtained by the student in 2nd semester");
    System.out.println("Enter number of grade points obtained by the student in English,Maths-2,maths-3,physics-2,chemistry-2,c++");
    for(i=1;i<7;i++)
    {
    a[i]=sc.nextInt();
    a[i]=(a[i]*3);
    a[i]=a[i]+a[i-1];
    }
    System.out.println("Enter number of grade points obtained by the student in Physics lab,c++ lab,Engg Graphics lab");
    for(i=1;i<4;i++)
    {
    b[i]=sc.nextInt();
    b[i]=(b[i]*2);
    b[i]=b[i]+b[i-1];
    }
    e=(a[6]+b[3])/24;
    System.out.println("SGPA Of the 2nd semester is"+(float)e);
    System.out.println("CGPA is"+(float)(d+e)/2);
    System.out.println("Enter number of grade points obtained by the student in 3rd semester");
    System.out.println("Enter number of grade points obtained by the student in BE,DMS,PSQT,FDL");
    for(i=1;i<5;i++)
    {
    a[i]=sc.nextInt();
    a[i]=(a[i]*3);
    a[i]=a[i]+a[i-1];
    }
    System.out.println("Enter number of grade points obtained by the student in Es and DS");
    for(i=1;i<3;i++)
    {
    b[i]=sc.nextInt();
    b[i]=(b[i]*4);
    b[i]=b[i]+b[i-1];
    }
    System.out.println("Enter number of grade points obtained in DS lab,Electronics lab and English lab");
    for(i=1;i<4;i++)
    {
    c[i]=sc.nextInt();
    c[i]=(c[i]*2);
    c[i]=c[i]+c[i-1];
    }
    f=(a[4]+b[2]+c[3]/26);
    System.out.println("SGPA Of the 3rd semester is"+(float)f);
    System.out.println("CGPA is"+(float)(d+e+f)/3);
    }
    }

  4. Anonymous 2 says:

    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.awt.image.*;

    public class str extends JApplet implements ActionListener {
    public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JApplet applet = new Ex6();
    frame.getContentPane().add(applet);
    applet.init();
    applet.start();
    frame.setSize(400,200);
    frame.show();
    }

    JTextField text = new JTextField(“Artan Potera”);
    JTextArea ta = new JTextArea(20, 80);

    public void init() {
    ta.setFont(new Font(“Monospaced”, Font.PLAIN, 20));
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(text, BorderLayout.CENTER);
    JButton b = new JButton(“Print”);
    b.addActionListener(this);
    p.add(b, BorderLayout.EAST);
    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(p, BorderLayout.NORTH);
    this.getContentPane().add(ta, BorderLayout.CENTER);
    }

    public void actionPerformed(ActionEvent e) {
    String s = text.getText();
    if (s != null) {
    BufferedImage bi = new BufferedImage(80,20,BufferedImage.TYPE_INT_BGR);
    Graphics2D g2 = (Graphics2D)bi.getGraphics();
    g2.setFont(new Font(“Serif”, Font.BOLD, 20));
    g2.drawString(s, 0, 16);
    Raster ras = bi.getData();
    ta.setText(“”);
    for (int row = 0; row < 20; row++) {
    String line = "";
    for (int col = 0; col 98) {
    line += “*”;
    } else {
    line += ” “;
    }
    }
    System.out.println(line);
    ta.append(line+”\n”);
    }
    }
    }
    }

  5. vck says:

    vegineti babuuuuuuuuuuu

  6. vck says:

    kaamadana

  7. Anonymous says:

    hahahahaa………..

  8. Anonymous says:

    rey……vck peru tho evadu ra aa commentlu….??

  9. raju says:

    arey errors vastunnay ra……

  10. raju says:

    arey how to compile welcome program

  11. Anonymous says:

    cgpa program lo 3rd semester lo line 77 lo brackets arrays lo matrame pettu….. nd cgpa program naku bane execute ayindi ra….

  12. Anonymous says:

    welcome program minimum kuda raledu…..sum1 post it!

  13. tom and jerry says:

    aasa dosa appadam vada…. :P

  14. aditya mehra says:

    can ne1 write the program of fcfs using pipes to stimulate fcfs???

  15. Madhvaraj says:

    Guyz… Can v make Program to run algorithm with premitive and non premitive.

  16. jamu bhutia says:

    can nybdy xplain d logic of above program?????????/

  17. NeedHelpURGENT! says:

    Can you help me with Last Come, First Served (LCFS) or Last In, First Out (LIFO)
    C program codes? Please. Many Thanks! :)

  18. mohsin khan says:

    Fcfs ka algo in c me chahiye plz btaona

  19. bobos says:

    wrong prog recompile it :(

  20. vinay says:

    teeri maaa ki

  21. viswas says:

    its good to understand dude

  22. hai says:

    hgafgsdrwteyyjhwhsjs jjshhsgd…………….??????????????”"”"”"”"”"”

  23. eman says:

    How can I write and run a FCFS algorithm using C++ knowing that these are the input info:

    Process ,burst time , waiting time

    (p1=burst 24 , wt 0)

    (p2=burst 15 = wt 24)

    (p3=burst 27, wt 39)

    (p4=burst 16, wt 66)

    (p5=burst 16, wt 82)

    Compute average time of waiting time for all processes
    Compute average time of turnaround time for all processes

    turn in your program to compute both time waiting time and turnaround time.
    The project at end will compute the average of both times to find best algorithm

    help me please ..

  24. Chaitanya says:

    Tried the same logic as shown.. but the problem arises with the total waiting time as well as average waiting time…

    they appear to be 0 in both the cases..

    Help me !! :(

  25. Wakapa says:

    shirtlu nehru garu poolu

  26. Wakapa says:

    adhaanlu naanlu!!!

  27. Duckilooo says:

    Chikangoka
    Spring roll
    Kabapp
    Vulkar
    Pissaa
    .
    .
    .
    .
    ituli vadaa pongaal dosaa

  28. Duckilooo says:

    neelu ennalu panralu…! poilu aduthalu semlu vaalu….
    neeelu indhalu collegelu continuelu pannalu mudiyathulu.. neelu veralu collgelu paarulu…

  29. Duckilooo says:

    endha saarae party la enna kalichuu..
    Saarae nyaan naan kalichuu..
    pachae neenga kalichadhum ariyum, enna sapadu kalichuu
    adhaan saarae naan thaan kalichuu..
    hehehehehhhehee ariyum saarae nyan vilayatu ku paranchuu..
    endha aayi saarae..
    Comedy paranchuu…
    (apdiyae serupala aranchuu…)

  30. shinde deepak says:

    the code is wrong because
    ” et ” is not declare instead of it replace “et ” to “pt “

  31. shinde deepak says:

    the code is wrong because
    ” et ” is not declare instead of it replace “et ” to “pt “
    and
    instead of char p[10][10]
    write p[10]
    ………………………………………………. :)

  32. gayathri says:

    i want fcfs program imediatly in java code

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup

Email: