i wrote the following code for implementing round robin
*// roundrobin.cpp :
#include <iostream>
using namespace std;
int main()
{
int numpros;
int temp=0;
cout<<"enter # of processes=";
cin>>numpros;
int twt=0;
int* wt=new int[numpros];
int* bt=new int[numpros];
int* eqs=new int[numpros];
int* remainder=new int[numpros];
int max=0;
int tbt=0;
int nfq=0;
int n,o,p,q,r;
cout<<"enter burst time of each proccess"<<endl;
for(q=0;q<numpros;q++)
wt[q]=0;
for(int i=0;i<numpros;i++)
{
开发者_运维百科 cout<<"burst time "<<i<<"=";
cin>>bt[i];
//tbt=bt[i]+tbt;
}
for(int j=0;j<numpros;j++)
{
cout<<"# of quantums of process "<<j<<"=";
eqs[j]=bt[j]/4;
remainder[j]=bt[j]%4;
if(eqs[j]>max)
{
max=eqs[j];
temp=j;
}
cout<<eqs[j]<<" "<<remainder[j]<<endl;
}
if(remainder[temp]>0)max++;
//cout<<max<<endl;
int tslicetime=numpros*4;
for(int m=0;m<max;m++)
{
for(n=0;n<numpros;n++)
{
if(bt[n]>4)
{
bt[n]=bt[n]-4;
for(o=0;o<numpros;o++)
{
if(o!=n && bt[o]>0)
{
wt[o]+=4;
}
}
}
else if(bt[n]<=4 )
{
for(p=0;p<numpros;p++)
{
if(p!=n && bt[p]>0)
{
wt[p]+=bt[n];
}
}
bt[n]=0;
}
cout<<"p"<<n<<"="<<bt[n]<<" ";
}
}
cout<<endl;
for(r=0;r<numpros;r++){
}
cout<<endl;
for(r=0;r<numpros;r++){
cout<<"waiting time "<<r<<"="<<wt[r]<<endl;
}
}
it is working fine on vs2010 but gcc is giving following error on compilation
moni@moni-laptop:~/codes$ g++ rr rr.cpp
rr: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here
rr:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here
rr: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here
rr:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
rr: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here
rr: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here
rr: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.init+0x0): first defined here
/tmp/ccB1Drkq.o: In function `main':
rr.cpp:(.text+0x0): multiple definition of `main'
rr:(.text+0xb4): first defined here
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
rr:(.dtors+0x4): first defined here
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
/usr/bin/ld: error in rr(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
You have g++ rr rr.cpp
but you want g++ -o rr rr.cpp
. You're trying to link the executable to itself, resulting in duplicate symbols.
精彩评论