Quantcast
Channel: Active questions tagged operating-system+scheduling - Stack Overflow
Viewing all articles
Browse latest Browse all 209

Why is my programme showing Segmentation Fault on Ubuntu but working fine on Geeks IDE?

$
0
0

Experts, this is the program I made for First Come First Serve Scheduling in C language.
For the inputs like -
4
0 0 0 0
1 2 3 4

and inputs like -
5
0 1 2 3 4
4 3 1 2 5

My program is giving Segmentation fault (Core dumped) when I tried running it on my Ubuntu but it worked fine on GeeksForGeeks IDE.
And for the inputs like -
6
4 3 2 1 2 3
4 3 2 3 4 5

My program is working fine on my Ubuntu as well as on GeeksForGeeks IDE.

#include<stdio.h>
void main(){
    int n,i;
    printf("\nEnter the number of jobs:\n");
    scanf("%d",&n);
    int at[n],bt[n],at_copy[n];
    printf("\nEnter the arrival time:\n");
    for(i=0;i<n;i++){
        scanf("%d",&at[i]);
        at_copy[i]=at[i];   
    }    
    printf("\nEnter the burst time:\n");
    for(i=0;i<n;i++)
        scanf("%d",&bt[i]);
    int priority[n],min=at_copy[0],k,j;
    for(j=0;j<n;j++){
        min=at_copy[0];
        for(i=0;i<n;i++){
            if(at_copy[i]<min){
                min=at_copy[i];
                k=i;
            }
        }
        at_copy[k]=999;
        priority[j]=k;
    }
    int ct[n],wt[n],tat[n],t=0;
    for(i=0;i<n;i++){
        if(at[i]<t)
            k=0;
        else
            k=at[i];
        t+=bt[i]+k;
        ct[i]=t;
        tat[i]=ct[i]-at[i];
        wt[i]=tat[i]-bt[i];
    }
    printf("\nProcess\tAT\tBT\tCT\tTAT\tWT\n");
    for(i=0;i<n;i++){
       printf("P%d\t%d\t%d\t%d\t%d\t%d\n",i+1,at[i],bt[i],ct[i],tat[i],wt[i]);
    }
}

In the output, I am expecting a table like structure displaying the arrival time, burst time, completion time, burst time, turnaround time and waiting time of all the processes.


Viewing all articles
Browse latest Browse all 209

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>