Need the commands n shell progs:
1. Display all the files in your current directory in upper case.
2. Display all the files with all attributes those have been created and modified in the month of August.
3. Write a shell script to read date and temperature of last 7 days and show the average temperature of last 7 days.
4. Write a shell script to make a calculator.
5. Write a program to send message through pipe.
6. Write a program for FCFS CPU scheduling algo.
7. Write a program for SJF CPU scheduling algo.
Plz help.
Hi There,
Well U can make FCFS/SJF in SHELL but during my first year I made it in c++.
Anyway You can also relate the c file to SHELL!
Here's the code for cpp file.
1. SJF :
*********
#include<iostream.h>
int n,time=0;
int *t=new int[n],*t1=new int[n];
int *arr=new int[n],*w=new int[n];
int sort(int pr[],int prt[],int c)
{
int i,tem,tem2,cmp=0;
for( i=0;i<(c-1);i++)
{
for(int j=(c-1);i<j;j--)
{
cmp++;
if(prt[j]<prt[j-1])
{
tem=prt[j]; tem2=pr[j];
prt[j]=prt[j-1]; pr[j]=pr[j-1];
prt[j-1]=tem; pr[j-1]=tem2;
}
else
continue;
}
}
return pr[0];
}
int sjf()
{
int i,j,c,*prt=new int[n],*pr=new int[n],proc;
for(i=0;i<time;i++)
{
c=0;
for(j=0;j<n;j++) //how many process r coming at i arrival time
{
if(arr[j]<=i && t[j]!=0)
{
pr[c]=j;
prt[c]=t[j];
c++;
}
else continue;
}
if(c==0) //If no process comes at i,increase waiting time
{
for(j=0;j<n;j++)
{
if(t[j]!=0 && arr[j]<i) w[j]++;
else continue;
}
}
else //else get the the shortest burst time t[] process
{
proc=sort(pr,prt,c);
t[proc]=0;
for(j=0;j<n;j++)
{
if(t[j]!=0 && arr[j]<i) w[j]++;
else continue;
}
}
}//end of time
return 0;
}
int main()
{
int i;
//cout<<"Enter the Number of Processes : "; cin>>n;
n=4;
t[0]=7;t[1]=4;t[2]=1;t[3]=4;
arr[0]=0;arr[1]=2;arr[2]=4;arr[3]=5;
for(i=0;i<n;i++)
{
w=0;
t1=t;
time=time+t;
}
sjf();
for(i=0;i<n;i++) cout<<"P["<<(i+1)<<"] "<<arr<<" "<<t1<<" "<<w<<endl;
return 0;
}
********
U can compile the same in gcc under linux!
2. FCFS :
********
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int n,i;
cout<<"Enter number of processes : ";
cin>>n;
int *a=new int[n],*t=new int[n],*arr=new int[n];
clrscr();
cout<<"Process\t "<<"Arrival time\t"<<" Burst time";
for(i=0;i<n;i++)
{
gotoxy(1,i+3); cout<<"P["<<(i+1)<<"]";
gotoxy(17,i+3); cin>>arr;
gotoxy(38,i+3); cin>>t;
}
int *w=new int[n],*trn=new int[n],tot=0,tot1=0,avw=0,avtrn=0,*res=new int[n];
for(i=0;i<n;i++) { w=0; res=0;}
gotoxy(1,n+6);
cout<<"\t\tF I R S T C OM E F I R S T S E R V E";
gotoxy(1,n+7);
cout<<"\nProcess\t "<<"Waiting time\t"<<" Turnaround Time\t"
<<" Response time"<<endl;
for(i=0;i<n;i++)
{
if(i==0) {trn=t;}
else
{
tot=tot+t[i-1];
w=tot-arr;
trn=w+t;
}
tot1=tot1+t;
res=tot1;
avw=avw+w; avtrn=avtrn+trn;
gotoxy(1,i+n+10); cout<<"P["<<(i+1)<<"]";
gotoxy(17,i+n+10); cout<<w;
gotoxy(37,i+n+10); cout<<trn;
gotoxy(62,i+n+10); cout<<res;
}
cout<<"\nAverage waiting time = "<<((float)avw/n)<<endl;
cout<<"Average turnaround time = "<<((float)avtrn/n)<<endl;
getch();
return 0;
}
********