对不起,如果我的英文很糟糕:我是realy stresed :( 我使用Ubuntu 11.04作为虚拟机使用VMWARE作为虚拟机操作系统是Windows 7。我试图用C语言编写一个Linux程序:使用共享内存,当我尝试编译时没有错误,但是当我执行它时,我看到如下错误: 分段错误(核心转储) I也不太清楚,但据我了解到VMware是导致此:S 这里是代码:关于VMWARE UBUNTU分割错误(核心转储)
#include<stdio.h>
#include<sys/wait.h> //Process wait
#include <fcntl.h> //File
//#include <cstdlib>
//#include<fstream.h>
int main(){
printf("\n Here we go...!");
int *Numbers;
Numbers=(int*)getmem(327); // shared memory
int i,ProcID;
ProcID=fork(); //depart processor
if(ProcID==0){ // child processor
for(i=0;i<50;i++){
Numbers[i]=random()%50;
}
}else if(ProcID<0){
printf("\n Hmm... There is an error!");
}
int Waiting;
wait(&Waiting);
if(ProcID>0){ // parent processor
int fileeven,fileodd;
fileeven=open("EK_even.txt",O_RDWR|O_CREAT,0600);
fileodd=open("EK_odd.txt",O_RDWR|O_CREAT,0600);
for(i=0;i<50;i++){
if(Numbers[i]%2==0){
write(fileeven,&Numbers[i],sizeof(Numbers[i]));
}else{
write(fileodd,&Numbers[i],sizeof(Numbers[i]));
}
}
close(fileeven);
close(fileodd);
}else if(ProcID<0){
printf("\n Hmm... There is an error!");
}
return 1;
}
我用这组合物1乐终端上:gcc的-o ./RUN ./EK.c -shared 运行:./ RUN 的结果是:分段故障(核心转储)
感谢您的时间和reponds我真的需要...
对于VMware来说,导致这样的错误会非常奇怪。显然,请尝试在VMware上运行的“真正”Linux安装上的代码进行确认。更可能的是你的代码有一个bug。 – 2011-05-25 15:09:55
thx的建议我会尝试这个如果作品,我会让你知道... – 2011-05-25 15:14:29
这是一个程序中的错误,它不是VMWare的错。你应该发布你的getmem()函数。也许你应该检查它是否失败。 open()调用也是如此,它们可能会失败。 – nos 2011-05-25 17:31:25