centos下 Segmentation fault 错误! 5C

centos 6.9 执行 yum、wget、oracle启动实例dbstart、sqlplus 等 操作都会报错:Segmentation fault;
请问是哪里出现了问题?

1个回答

这是硬件错误,说明应该是存储文件/程序的物理存储出现损坏,可以搜索一下硬件回复工具,或者干脆重装系统。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
fgets()错误:Segmentation fault
用C编了一个小的程序,运行环境是linux。编译通过,但在运行的时候出现Segmentation fault!rnrnvoid do_more(FILE *fp)rnrnchar line[NUM];rnwhile(fgets(line, NUM, fp))rnrn……rnrnrnrn通过调试问题应该是出现在 fgets(line, NUM, fp); 这一句。rnrn调试中发现,循环中如果第一次执行这条语句没问题,rn但是到了第二次执行这条语句的时候程序就跳出来了,并输出Segmentation fault 。rnrn网上找到的可能原因是:1,数组越界.2,访问空,野指针或未被初始化的指针.rn可是问题还是不知道怎么解决,希望各位大大给帮帮忙!!
segmentation fault 的错误
编程中,遇到以下错误:程序的结构是这样的rn调用一个文件分割的函数split()rnwhile()rn ...rnrn循环只执行了一次,就出现segmentation fault的错误。rn但是,如果程序结构是:rnwhile()rn split() rn ....rnrn则程序在执行了若干次以后才出现此错误。rn请教各位,这是什么原因呢?急!在线等!rnrnrn
奇怪的segmentation fault 错误!!!!!!!!!!!!!!
下面这段代码在tc2.0下编译运行,结果正确。但在redhat9.0下用gcc编译通过,运行时出现rnsegmentation fault 错误,怎么回事????gcc编译器检查如此严格?????rnrnrnrn#include rnrn int main()rn rn char *s="Golden Global View";rn char d[20];rn rn //clrscr();rn rn //strcpy(d,s);rn //printf("%s",d);rn rn memset(s,'w',4);rn printf("%s",s);rn rn rnrn getchar();rn return 0;rn
segmentation fault :11错误
用Mac,C语言写作业,在Xcode里面可以良好运行在terminal里面缺会出错不知道为什么,而且安装之后总是不能使用gdb所以也不知道怎么找到出错的语句,本人纯小白希望各位大大能帮助我一下。。。rn[code=c]rnrn#include rn#include rn#include rn#include rn#include rn#include rnrnchar s1[]="1";rnchar s2[]="1";rnrnrnint main(int argc, const char * argv[])rnrn char buf1[256],a[256]=0,b[256],c[256];rn rn int p1[2],p2[2],p3[2],p4[2];rn int parentw1,parentw2, child1r,child2r,parentr1,parentr2,child1w,child2w,pid;rn pipe(p1);rn pipe(p2);rn pipe(p3);rn pipe(p4);rn child1r=p1[0];rn child2r=p2[0];rn parentw1=p1[1];rn parentw2=p2[1];rn rn parentr1=p3[0];rn parentr2=p4[0];rn child1w=p3[1];rn child2w=p4[1];rn rn if (fork()==0) rn /*first child process--adder*/rn pid=getpid();rn FILE *fd;rn char s[]="stopstop";rn close(parentw2);close(parentw1);close(parentr1);close(parentr2);close(child2r);close(child2w);rn int f;rn rn int i=0;rn rn int sum=0;rn rn int k[1024];rn rn while (1) rn read(child1r, buf1, sizeof(b)); //get the number of fieldrn rn f=atoi(buf1);rn read(child1r, buf1, sizeof(b)); //get the name of filern rn sscanf(buf1, "%s",a);rn rn rn if (strcmp(a,s)==0) //compare to find wether the file name is stopstop if it is ,then break and teminatern rn break;rn rn rn fd=fopen(a, "r");rn while (!feof(fd)) rn fscanf(fd, "%d",&k[i]); //get all the numbers in the file then calculate the modrn i++;rn rn for (int i=1; i<=k[0]; i++) rn sum+=(k[i]%f); //sum the result of modrn rn rn printf("my ID is:%d ",pid);rn printf("file name is:%s ",a);rn printf("%d\n",sum);rn write(child1w, s1, sizeof(s1));rn rn // write(childw1, s1, sizeof(s1));rn rn exit(1);rn rn rn elsern rn if (fork()==0) rn /*second child process--factorial*/rn pid=getpid();rn rn int x,fac;rn int f ;rn int k = 0;rn rn close(parentw1);close(parentw2);close(parentr2);close(parentr1);close(child1r);close(child1w);rn while (1) rn read(child2r, buf1, sizeof(b));rn rn rn f=atoi(buf1);rn rn read(child2r, buf1, sizeof(b));rn rn x=atoi(buf1);rn rn rn rn if (f==0) rn break;rn rn k=x;rn for (int i=1; i
setjmp SEGMENTATION FAULT 错误。
linux环境下,程序中调用setjmp。运行此程序,出现Segmentation fault 错误,rn删掉setjmp调用程序运行正常。rn换成sigsetjmp()也出现同样错误。rnrn而且我已经把 setjmp函数放在最靠近main()入口的地方了,还是出错。rn其他小程序:调用setjmp的都运行正常。rnrn查了网上的资料,有说这个bug的。但是我也没给返回值赋值。rnThis is a very common bug with setjmp() and longjmp() -- to use them properly, you CANNOT RETURN FROM THE PROCEDURE THAT CALLS setjmp(). rnrnURL:http://www.cs.utk.edu/~plank/plank/classes/cs360/360/notes/Setjmp/lecture.html
Segmentation fault错误
[code=C/C++]rn#include rn#include rn#include rn#include rn#include rn#include rnrnint main()rnrn struct DIR *dp;rn struct dirent *temp_dp;rn char temp_name[NAME_MAX+1];rn struct stat temp_stat;rn int temp_fd;rnrn dp=opendir("/dev/");rn if(dp==NULL)rn fprintf(stderr,"open /dev/ dir error");rn exit(0);rn rn strcpy(temp_name,"/dev/");rn rn while((temp_dp=readdir(dp))!=NULL)rn strncpy(temp_name+sizeof("/dev/")-1,rn temp_dp->d_name,NAME_MAX);rn if(strcmp(temp_name,"/dev/.")==0 || strcmp(temp_name,rn "/dev/..")==0)rn continue;rn if((temp_fd=open(temp_name,O_RDONLY))<0)rn fprintf(stderr,"open file %s error\n",temp_name);rn exit(0);rn rn if(stat(temp_name,&temp_stat)<0)rn fprintf(stderr,"get file %s stat error\n",temp_name);rn exit(0);rn rnrn if(isastream(temp_fd))rn printf("%s is a stream device ",temp_name);rn rn if(S_ISREG(temp_stat.st_mode))rn printf("and regular file");rn else if(S_ISDIR(temp_stat.st_mode))rn printf("and dir file");rn else if(S_ISCHR(temp_stat.st_mode))rn printf("and charact device file");rn else if(S_ISBLK(temp_stat.st_mode))rn printf("and block device file");rn else if(S_ISFIFO(temp_stat.st_mode))rn printf("and fifo file");rn rn printf("\n");rn rn close(temp_fd);rn rnrnrn[/code]rn怎么输出Segmentation fault错误?
segmentation fault错误求解
程序运行时碰到了segmentation fault,程序的大体意思是,当接收到客户端发送来的'S'字符时,启动另外一个线程来发送58张图片,send_data函数在前17次接收到'S'字符发送图片时不会出问题,但到第18次发送第33张图片时会出现segmentation fault错误,多次测试都是第18次发送第33张图片时出现问题,请大家帮帮忙找找啥原因,谢谢!rn程序: rnmain()rn rn//其他程序rnrn if('S'==buffer[0]) rn rn pthread_t thread; rn if(pthread_create(&thread,NULL,send_data,&client_socket)!=0)//当接收到S字符时,启动多线程发送图片rn printf("Build thread failed!\n");break; rn rnrn/////////////////////////////////////////////////////////////////////////////////////rnvoid *send_data(void *socket)rnrn int ret=0;rn int client_socket;rn char sendbuffer[BUFFER_SIZE];rn char compare[]="finshed";rn char file_name[40];rn char file_size[30];//store the file size,and send to the clientrn FILE *file_fd=NULL;rn long int file_len;rn int send_num=0;rn int i,j,num;rnrn client_socket=*((int *)socket);rnrnfor(j=1;j
关于Segmentation fault的错误
为什么下面的代码执行时第1,3,4行会报Segmentation fault的错误,而第2行不报错rn1、//if (!strcmp(row[1], "")) printf("(strcmp)field question's value is string ''");rn2 if (strlen(row[1]) == 0) printf("(strlen)field question's value is string ''");rn3 //if (!strcmp(row[2], "")) printf("field answer's value is string ''");rn4 //if (!strcmp(row[3], "null")) printf("field joinaddr's value is string null");
Segmentation fault错误求教
这个是报错rnProgram received signal SIGSEGV, Segmentation fault.rn0x001c74a5 in std::basic_string, std::allocator >::basic_string(std::string const&) () from /usr/lib/libstdc++.so.6rn(gdb) wherern#0 0x001c74a5 in std::basic_string, std::allocator >::basic_string(std::string const&) () from /usr/lib/libstdc++.so.6rn#1 0x0804b444 in Time::getTOD (this=0x0) at Time.cpp:63rn#2 0x0804a4f0 in main (argc=2, argv=0xbffff7a4) at printsongs.cpp:102rn(gdb) frame 1rn#1 0x0804b444 in Time::getTOD (this=0x0) at Time.cpp:63rn63 return timeofday;rn(gdb) frame 2rn#2 0x0804a4f0 in main (argc=2, argv=0xbffff7a4) at printsongs.cpp:102rn102 << T->getMinute() << " " << T->getTOD() << endl;rn(gdb)rnrn错误的代码所在地rnSong s = songs.getNthSong (n);rnSong defaultSong;rnrn// Print out the last time it was playedrnif (!(s == defaultSong) ) rnTime *T = s.getLastPlayed();rncout << "Song #" << n << " is " << s.getTitle() << " by "rn<< s.getArtist() << ". Last played at " << T->getHour() << ":"rn<< T->getMinute() << " " << T->getTOD() << endl;rnrnrnrnstring Time::getTOD()rnrnreturn timeofday;rnrnrnSegmentation fault 这个错误是在我加入 下面这段话后出错误的.加入这段代码是要处理double free的错误rnrnSong& Song::operator =(const Song &so)rnrnrnif(last_played==0)rnlast_played=0;rnrnelsernif(last_played!=0)rndelete last_played;rnrnlast_played=new Time (*so.getLastPlayed());rnrnartist=so.getArtist();rntitle=so.getTitle();rnrnrnrnrn[code=C/C++]rn//Time.cpprnrn#include "Time.h"rnrn//rn// Name: (constructor)rn//rnrnTime::Time (int h, int m, string tod) : hour(h), min (m), timeofday(tod)rnrn // Value check rn if ((h < 1) || ( h > 12) || (m < 0) || ( m > 59) || rn ((tod != "am") && (tod != "pm"))) rn hour = 12;rn min = 1;rn timeofday = "am";rn rnrnrn//rn// Name: (copy constructor)rn//rnTime::Time (const Time &T) : hour (T.hour), min (T.min), rn timeofday (T.timeofday) rnrnrnrnrn//rn// Name: getHourrn//rnint Time::getHour()rnrn return hour;rnrnrnrn//rn// Name: getHourrn//rnint Time::getMinute()rnrn return min;rnrnrn//rn// Name: getTODrn//rnrnstring Time::getTOD()rnrn return timeofday;rnrnrnrn//Song.cpprnrn#include "Song.h"rn#include "Time.h"rnrn//rn// Name: (default constructor)rn//rnSong::Song() : artist ("none"), title ("none"), last_played (0) rnrnrn//rn// Name: (constructor)rn//rnSong::Song (string t, string a) : artist (a), title (t), last_played (0) rnrnrnrn//rn// Name: (destructor)rn//rnSong::~Song()rnrn if (last_played != 0) delete last_played;rnrnrnrn//rn// Name: operator==rn//rnbool Song::operator== (const Song &S)rnrn // Two songs are equal if their titles and artists are equalrn return ((title == S.title) && (artist == S.artist));rnrnrnrn//rn// Name: getArtistrn//rnstring Song::getArtist() constrnrn return artist;rnrnrn//rn// Name: getTitlern//rnstring Song::getTitle() constrnrn return title;rnrnrnrnrn//rn// Name: playrn//rnvoid Song::play (Time *T)rnrn last_played = T;rnrnrnrn//rn// Name: getLastPlayedrn//rnTime *Song::getLastPlayed () constrnrn return last_played;rnrnrnrn//operator= methodrnSong& Song::operator =(const Song& so)rnrnrnif(last_played==0)rn last_played=0;rnrnelsern if(last_played!=0)rn delete last_played; rn rn last_played=new Time (*so.getLastPlayed());rnrnartist=so.getArtist();rntitle=so.getTitle();rnrnreturn *this;rnrnrnrn//printsongs.cpprnrn#include rn#include rn#include rn#include "Song.h"rn#include "SongList.h"rnrnusing namespace std;rnrnrn// usage: printsongs nrn//rnint main (int argc, char * const argv[]) rnrn // Commandline checkrn if (argc != 2) rn cerr << "usage: printsongs n" << endl;rn return(1);rn rnrn // Convert commandline argument to intrn istringstream arg1 (argv[1]);rn int n;rn arg1 >> n;rn if (!arg1) rn cerr << "usage: printsongs n" << endl; rn cerr << "n must be an integer" << endl;rn return(1);rn rn rn // check for positive input valuern if ( n < 1 ) rn cerr << "n must be positive" << endl;rn return(2);rn rnrn // Create a song listrn SongList songs(10);rn rn // Play some songsrn songs.play (Song ("Only Time Will Tell", "Asia"), rn new Time (10,12,"am"));rn songs.play (Song ("You'll Think of Me", "Keith Urban"), rn new Time (10,20,"am"));rn songs.play (Song ("What I Like About You", "The Romantics"), rn new Time (10,25,"am"));rn songs.play (Song ("Stairway to Heaven", "Led Zepplin"), rn new Time (10,30,"am"));rn songs.play (Song ("Roundabout", "Yes"), rn new Time (10,45,"am"));rn songs.play (Song ("I Do the Rock", "Tim Curry"), rn new Time (10,55,"am"));rn songs.play (Song ("Better Days", "Goo Goo Dolls"), rn new Time (11,02,"am"));rn songs.play (Song ("There's No Business Like Show Business", "Ethel Merman"),rn new Time (11,30,"am"));rn songs.play (Song ("What I Like About You", "The Romantics"), rn new Time (11,35,"am"));rn songs.play (Song ("Twist and Shout", "The Beatles"), rn new Time (11,39,"am"));rn songs.play (Song ("Taxi", "Harry Chapin"), rn new Time (12,12,"pm"));rn rn rn // get the nth song playedrn Song s = songs.getNthSong (n);rn Song defaultSong;rn rn // Print out the last time it was playedrn if (!(s == defaultSong) ) rn Time *T = s.getLastPlayed();rn cout << "Song #" << n << " is " << s.getTitle() << " by " rn << s.getArtist() << ". Last played at " << T->getHour() << ":" rn << T->getMinute() << " " << T->getTOD() << endl;rn rnrn return 0;rnrnrn[/code]
Segmentation fault是什么错误?
在程序中,执行一定的地方就出现这个错误:rnSegmentation faultrn我发现出错的语句是sprintf和printf,vsprintf之类的,请问这是怎么回事?rn请指点!
Segmentation fault错误!十万火急!
我向一个文本文件插入一万条字符串,用的是fputs函数,i=fputs(name,fp);rnchar name[9];rn程序运行后就出现这个Segmentation fault错误,实际上文件更本就只写进去1千多条,远远未达到目标要求!rnrnrnrn我该怎么办?请大侠指点迷津rnrn rn rn 谢谢!
Segmentation fault (core dumped)错误!!!
急急~~~~!!!!rn 我在LIUNX建C++程序,,,连接SQL的....rn 通过g++ -sybdb * 通过编译后生成a.outrn 但当我运行a.out 时却出现"Segmentation fault (core dumped)"错误,,rnrn 各位大侠..帮帮忙了.....rnrn在线等待你的付佳音....
segmentation fault
请问各位大牛,为什么我的代码运行后会出现这样的错误呢?rn我是在linux下编译运行的,用的是gcc编译rn这是我的代码:rn#include rn#include rn#include rnrn#define M 5rn#define K 4rn#define N 3rnint A[M][K],B[K][N],C[M][N];rnrnstruct myparrnrn int row;rn int line;rn;rnrnvoid* Times(struct mypar arg)rnrn //struct mypar * newpar = (struct mypar *)arg;rn int row,line;rn int i;rn row = arg.row;rn line = arg.line;rn C[row][line] = 0;rn for(i = 0;i < K;i++)rn C[row][line] += A[row][i]*B[i][line];rnrnrnvoid main()rnrn int i,j;rn for(i = 0;i < M;i++)rn for(j = 0;j < K;j++)rn scanf("%d",&A[i][j]);rn for(i = 0;i < K;i++)rn for(j = 0;j < N;j++)rn scanf("%d",&B[i][j]);rn pthread_t id[M][N];rn for(i = 0;i < M;i++)rn for(j = 0;j < N;j++)rn rn struct mypar par;rn par.row = i;rn par.line = j;rn pthread_create(&id[i][j],NULL,(void*)Times(par),NULL);rn rn for(i = 0;i < M;i++)rn for(j = 0;j < N;j++)rn pthread_join(id[i][j],NULL);rn for(i = 0;i < M;i++)rn for(j = 0;j < N;j++)rn rn if(j == N-1)rn printf("%d\n",C[i][j]);rn elsern printf("%d ",C[i][j]);rn rnrnrnrn我输入了rn1 1 1 1 rn1 1 1 1 rn1 1 1 1 rn1 1 1 1rn1 1 1 1 rnrn1 1 1rn1 1 1rn1 1 1rn1 1 1rn运行后就显示段错误了。
segmentation fault!!!
下面是我写的一个将一定长以内的十进制转换为十六进制的程序,基本的思想就是模拟手动转换的过程。不断地除以十六(下一次以商进行),得商和余数,把余数悉数存入一个数组,然后逆序输出。结果输出是正确的,可是在linux下运行最后报segmentation fault,在windows下运行显示结果后就似乎停不下了,而且CPU100%。尤其数很大的时候,似乎是动态内存处理的问题,可我就是看不出来问题在哪。哪位帮忙看看。谢谢。rnrn#include "iostream"rnusing namespace std;rnint residue(int *,char *,int,int);rnint main(void)rnrn int n,i,l=0,c,j;rn char **p;rn cin>>n;rn int *r=new int[n];rn p=new char *[n];rn for(i=0;i>p[i];rn rn for(i=0;i=0)//逆序输出rn rn if(r[c]<10)//十六进制,如果小于10,直接输出rn rn cout<=16)?(l--,t):(l-=2,flag++,t*10+p[2]);//像173,前两位够除以16,就拿17除,这时下一步要处理的是2,从0开始计数就是第二位;像1525,前两位15不够,加上第三位2再除。这时下一步要处理的就是5,第三位。rn for(j=0;j
Segmentation fault
[size=10px] char *bufferA = (char*)malloc( 100* sizeof(char) );rn rnrn .......rnrn bufferA 被字符填充...略过rnrn .........rnrn [color=#FF0000]char *bufferB = (char*)malloc( 100* sizeof(char) );rn char *temp = (char*)malloc( 10 * sizeof(char) );rn strcpy(bufferB , bufferA ); rn sprintf(temp , "%d", 159);[/color]rnrn问题:出现Segmentation fault[/size]rn
Segmentation fault~~
~_~ 終於做好了我的my_printf, 但是當我在main裡這樣輸入的話 :rn#include rn#include "my_printf.h"rnrnint main()rnrn my_printf("%s\n", 'c');rn //printf("%s", 'c'); rn return (0);rnrnrn就 Segmentation fault,rn我知到%s对应的应该是个字组, 但是有什麽办法预防呢?
Segmentation Fault错误原因总结
一、 什么是“Segmentation fault in Linux”所谓的段错误就是指访问的内存超过了系统所给这个程序的内存空间,通常这个值是由gdtr来保存的,他是一个48位的寄存器,其中的32位是保存由它指向的gdt表,后13位保存相应于gdt的下标,最后3位包括了程序是否在内存中以及程序的在cpu中的运行级别,指向的gdt是由以64位为一个单位的表,在这张表中就保存着程序运行的代码段以及数据
gcc编译出现segmentation fault的错误
segmentation fault 即段错误,一般都是出现了非法的地址写操作导致的。 常见的有如下几种情况: 1、空指针访问。 如果指针为空(NULL), 那么对空指针的读写操作都会导致segmentation fault。 如 1 2 3 char *p = NULL; printf("%c",*p);//读操作
Segmentation fault (core dumped)错误
错误信息[img=https://img-bbs.csdn.net/upload/201706/12/1497257195_384428.png][/img]rnrn请问一下是什么原因?
Segmentation Fault
#includern#includern#includern#includern#includernusing namespace std;rnrnstruct Listrnrn List *prev;rn List *next;rn string name;rn friend bool operator < (List a, List b)rn rn return a.name>n)rn rn map_m;rn map::iterator it;rn List *_l, *Head;rn Head = new List;rn _l = new List;rn _l->name = "Last";rn _l->next = NULL;rn _l->prev = Head;rn Head->next=_l;rn Head->name = "Head";rn for(int i=0; i>tmp;rn if(tmp == "new")rn rnrn cin>>tmp;rn List *_l_tmp;rn _l_tmp = new List;rn _l_tmp->name = tmp;rn rn rn _l_tmp->next = Head->next;rn _l_tmp->prev = Head;rn Head->next = _l_tmp;rn _l_tmp->next->prev = _l_tmp;rn _m.insert(map::value_type(_l_tmp->name, _l_tmp));rn rn else if(tmp == "reply")rn rn cin>>tmp;rn it = _m.find(tmp);rn rn List *Prev, *Next;rnrn rn Prev = it->second->prev;rn Next = it->second->next;rnrn if(Prev != NULL && Next != NULL)rn rn Prev->next = Next;rn Next->prev = Prev;rn rn rn it->second->next = Head->next;rn it->second->prev = Head;rn Head->next = it->second;rn it->second->next->prev = it->second;rn rn else if(tmp == "tag")rn rn cin>>tmp;rn it = _m.find(tmp);rn rn List *Prev, *Next;rn rn Prev = it->second->prev; rn Next = it->second->next;rn rn Prev->next = Next;rn Next->prev = Prev;rn rn it->second->next = it->second->prev = NULL;rn rnrn rn else if(tmp == "search")rn rn List *q;rn q = Head->next;rn int Sum=0;rn while(q->next != NULL)rn rn cout<name<= 100) break;rn q = q->next;rn rn cout<<"###"<
segmentation fault (core dumped)错误
[code=C/C++][/code]rn#includern#define MAXROW 100rn#define MAXCOL 100rnrntypedef struct rn char pixels[MAXROW][MAXCOL];rn int m;rn int n;rngraph;rnrnvoid create(int m,int n,graph *g);rnvoid clear(graph *g);rnvoid colorOne(char s[][MAXCOL],int x,int y,char c);rnvoid vertical_pixels(char s[][MAXCOL],int x,int y1,int y2,char c);rnvoid horizontal(char s[][MAXCOL],int x1,int x2,int y,char c);rnvoid kRectangle(char s[][MAXCOL],int x1,int y1,int x2,int y2,char c);rnvoid fRegion(graph *g,int x,int y,char c);rnvoid sName(graph *g,char *name,FILE **f);rnvoid print(FILE **f,char *name);rnrnint main()rnrngraph g;rnchar str[20];rnFILE *f=NULL;rnwhile(1)rnrn gets(str);rn if(str[0]=='X')rn break;rn switch(str[0])rn rn case 'I':rn rn create(str[2]-'0',str[4]-'0',&g);rn break;rn rn case 'C':rn rn clear(&g);rn break;rn rn case 'L':rn rn colorOne(g.pixels,str[2]-'0',str[4]-'0',str[6]);rn break;rn rn case 'H':rn rn horizontal(g.pixels,str[2]-'0',str[4]-'0',str[6]-'0',str[8]);rn break;rn rn case 'V':rn rn vertical_pixels(g.pixels,str[2]-'0',str[4]-'0',str[6]-'0',str[8]);rn break;rn rn case 'K':rn rn kRectangle(g.pixels,str[2]-'0',str[4]-'0',str[6]-'0',str[8]-'0',str[10]);rn break;rn rn case 'F':rn rn fRegion(&g,str[2]-'0',str[4]-'0',str[6]);rn break;rn rn case 'S':rn rn sName(&g,&str[2],&f);rn print(&f,&str[2]);rn break;rn rn default:rn break;rn rnrnreturn 0;rnrnrnvoid create(int m,int n,graph *g)rnrnint i,j;rng->n=n;rng->m=m;rnfor(i=1;i<=n;i++)rn for(i=1;i<=m;i++)rn g->pixels[i][j]='O';rnrnrnvoid clear(graph *g)rnrnint i,j;rnfor(i=1;i<=g->n;i++)rn for(j=1;j<=g->m;j++)rn g->pixels[i][j]='O';rnrnrnvoid colorOne(char s[][MAXCOL],int x,int y,char c)rnrns[y][x]=c;rnrnrnvoid horizontal(char s[][MAXCOL],int x1,int x2,int y,char c)rnrnint i;rnfor(i=x1;i<=x2;i++)rn s[y][i]=c;rnrnrnvoid vertical_pixels(char s[][MAXCOL],int x,int y1,int y2,char c)rnrnint i;rnfor(i=y1;i<=y2;i++)rn s[i][x]=c;rnrnrnvoid kRectangle(char s[][MAXCOL],int x1,int y1,int x2,int y2,char c)rnrnint i,j;rnfor(i=y1;i<=y2;i++)rn for(j=x1;j<=x2;j++)rn s[i][j]=c; rnrnrnvoid fRegion(graph *g,int x,int y,char c)rnrnint i,j;rnchar col;rncol=g->pixels[y][x];rnfor(i=1;i<=g->n;i++)rn for(j=1;j<=g->m;j++)rn rn if(g->pixels[i][j]==col)rn g->pixels[i][j]=c;rn rnrnrnvoid sName(graph *g,char *name,FILE **f)rnrnint i,j;rn*f=fopen(name,"w");rnif(*f == NULL)rnrn return;rnrnfor(i=1;i<=g->n;i++)rnrn for(j=1;j<=g->m;j++)rn rn fputc(g->pixels[i][j],*f);rn rn fputc('\n',*f);rnrnfclose(*f);rnrnrnvoid print(FILE **f, char *name)rnrnprintf("%s\n",name);rn*f=fopen(name,"r");rnif(*f == NULL)rnrn return;rnrnprintf("%c",fgetc(*f));rnfclose(*f);rnrn
segmentation fault 错误 代码如下
在REDHAT 4.2 下使用gcc编译器编译通过,但是运行时出现segmentation fault错误提示,请指教:(读取8G数据到内存并打印到屏幕,运行时出现time 0: 6 ……time 4: 6 DATA1: segmentation fault)rn#define _CRT_SECURE_NO_DEPRECATE 1rnrn#include rn#include rn#include rn#include rnrnunsigned int *data1;rnunsigned int *data2;rntime_t time_0;rnrnint main()rnrn FILE *fp;rn int i;rn unsigned long long n, data_size;rn char file_name[32];rnrn // data1 申请5G空间rn data1 = (unsigned int *)malloc( ((unsigned long long)5)<<30 );rn // data2 申请3G空间rn data2 = (unsigned int *)malloc( ((unsigned long long)3)<<30 );rnrn time( &time_0 );rn data_size = 0;rn for(i=0; i<5; i++)rn rn sprintf(file_name, "%d.dat", i);rn if( (fp=fopen(file_name, "rb")) == NULL )rn rn printf("Can not open the file %s!\n", file_name);rn exit(1);rn rnrn n = fread(data1+data_size, 4, 1<<28, fp);// 1<<30rn data_size += (n<<7);rnrn fclose(fp);rn rn printf("time %d: %8ld\n", i, time(0)-time_0);rn rnrn printf("DATA1:\n");rn for(i=0; i<20; i++)rn rn printf("%08x\n", data1[data_size-(1<
Segmentation fault???
在程序运行的时候,出现这种错误,什么意思。rn为什么在编译的时候没有出现??rn下面的程序为什么会出现这种错误。rnrn#include rnmain()rnrnchar string[100];rnint seconds=1000;rnchar *string_change;rnchar *string_last;rnrnsprintf(string,"%d",seconds);rnstring_change=&string[0];rnprintf("string_change is %s\n",string_change);rnstrcat(string_last,string_change); //程序走到这就出现 Segmentation fault 的错误。郁闷!!!rnprintf("string_last is %s\n",string_last); rnrnrnrn如上的错误是否可以避免,如何去做,真心求教!!!rn顺便说一下。我是用gcc去编译的。rn晕死。这种错误时常出现,我一直都没有将其解决。。。。rn每次运行的时候见到这几个字,都想把它给吃了。。。
Segmentation fault?
#include rn#include rn#include rnvoid mythread(void) /* 定义新线程运行的函数 */rnrn int i,ret;rn ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); /* 设置线程的取消状态 */rn if(ret != 0)rn rn printf("Thread pthread_setcancelsate failed."); /* 如果取消状态未设置成功,打印错误信息 */rn exit(1);rn rn ret = pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); /* 设置线程的取消类型 */rn if(ret != 0)rn rn printf("Thread pthread_setcanceltype failed."); /* 如果取消类型未设置成功,打印错误信息 */rn exit(1);rn rn for(i=0; i<10; i++) /* 连续输出字符串,同时显示运行位置 */rn rn printf("Thread is running (%d) ...\n",i);rn sleep(1);rn rn pthread_exit("Thank you for the CPU time.\n"); /* 终止当前线程 */rnrnint main(void)rnrn pthread_t id; /* 定义线程的标识符 */rn int i, ret;rn void *thread_retult; /* 定义指针,用来存储线程的返回值 */rn ret = pthread_create(&id, NULL, (void *)mythread, NULL); /* 创建新的线程 */rn if(ret != 0)rn rn printf("Create pthread error.\n"); /* 如果线程创建失败,打印错误信息 */rn exit(1);rn rn sleep(3);rn printf("Canceling thread ...\n");rn ret = pthread_cancel(id); /* 取消新建线程 */rn if(ret != 0)rn rn printf("Thread cancelation failed.\n"); /* 如果线程取消失败,打印错误信息 */rn exit(1);rn rn sleep(2); rn /* 主线程阻塞,等待新建线程返回,并将返回值存储在前面定义的thread_result之中 */rn pthread_join(id,&thread_retult);rn printf("Thread joined, it returned: %s", (char *)thread_result); /* 输出线程返回的字符串 */rn return 0;rnrnrnrn经过编译后运行出现:rnrnThread is running(0)...rnThread is running(1)...rnThread is running(2)...rnCanceling thread....rnSegmentation faultrnrn[b]下面是我的想法:[/b]rn我觉得“新进程”终止时如果调用的是:rnpthread_exit("Thank you for the CPU time.\n"); /* 终止当前线程 */rn那么执行:rnpthread_join(id,&thread_retult);rn后自然把返回的字符串传递给thread_retult指针,但是此例程调用的是:rnret = pthread_cancel(id); /* 取消新建线程 */rn也就是说进程结束时并没有执行:rnpthread_exit("Thank you for the CPU time.\n"); /* 终止当前线程 */rn所以thread_retult指针是有问题的!rnrn经过测试,进程是被正常取消的了,只要输出不是(char *)thread_result,都能正常输出。rnrn但是具体什么问题,如何解决并不知道!同时也不知道自己理解的对不对!本人纯菜鸟一枚,求大神指教!
centos 安装bin文件报错segmentation fault
centos 安装bin文件报错segmentation fault
CentOS系统运行C++程序出现内存错误 segmentation fault
由于数据量比较大,几十万条的数据,读出来以binary的形式存储,会有40G。在每次读数据的时候总会出现些错误,现将遇到的有关内存错误整理一下。 参考博客 http://www.cnblogs.com/justacoder/archive/2010/04/14/segmentation_fault.html 出现segmentation fault的可能原因1.内存访问越界a) 由于使用错误的下标
Segmentation fault问题
//c语言实现输入任意长度的字符串n#include n#include nint main (void )nnchar *string = NULL ,*temp = NULL;nchar ch;nint i;n//先将字符串初始化为空nstring = (char *)malloc(1);nstring[0] = '\0';n//len为实际长度(包括空字符)nint len = 1;nwhile ((ch = getchar())!= '\n')nn //申请一个新字符串n temp = (char *)malloc(len+1);n if (temp = NULL)n n printf("内存不足!");n free(string);n exit(0);n n i=0;n while (string[i] != '\0'&&i
段错误 segmentation fault ?
#includern#includern#includern#includern#includern#includernrnEXEC SQL BEGIN DECLARE SECTION;rn varchar usr[20];rn varchar pass[20];rn varchar serv[20];rnEXEC SQL END DECLARE SECTION;rnrnint connect() rn EXEC SQL WHENEVER SQLERROR GOTO error_msg; rnrn EXEC SQL CONNECT :username IDENTIFIED BY :password USING :serv; rn printf("Connect successed!\n"); rn return 0; rnerror_msg: rn printf("Connect failed\n"); rn return -1;rnrnrnvoid sql_error(char *msg)rnrn char err_msg[128];rn size_t buf_len, msg_len;rn EXEC SQL WHENEVER SQLERROR CONTINUE;rn printf("\n%s\n", msg);rn buf_len = sizeof (err_msg);rn sqlglm(err_msg, &buf_len, &msg_len);rn printf("%.*s\n", msg_len, err_msg);rn EXEC SQL ROLLBACK RELEASE;rn exit(-1);rnrnrnint main ()rn EXEC SQL BEGIN DECLARE SECTION;rn char name[50];rn int id,score;rn EXEC SQL END DECLARE SECTION;rnrn strcpy(usr.arr,"qgtg");rn usr.len=(unsigned short)strlen((char *)usr.arr);rnrn strcpy(pass.arr,"qgtg");rn pass.len=(unsigned short)strlen((char *)pass.arr);rnrn strcpy(serv.arr,"6.0.55.10");rn serv.len=(unsigned short)strlen((char *)serv.arr);rn if (connect()!=0) rn exit(-1);rn EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n");rnrn printf("\n/*-------------------SELECT--------------------*/\n");rn printf("please input studentid:");rn scanf("%d",&id);rn EXEC SQL SELECT id,name,score INTO :id,:name,:score FROM student WHERE id=:id;rn printf("id=%d name=%s score=%d\n",id,name,score);rn EXEC SQL COMMIT WORK RELEASE;rn exit(0);rn
QT mini2440 Segmentation fault
我将QT的程序移植到mini2440开发板上原来一直好好地,为什么突然提示我“Segmengtion fault”,有人遇到过吗?
segmentation fault,求高手!
这是服务器端的程序:rn[code=C/C++]rn#include rn#includern#includern#includern#includern#includern//#includern#includern#define PORT 8888rn#define BACKLOG 2rnvoid process_conn_server(int s);rnint main(int argc, char *argv[])rnrn int ss,sc;rn struct sockaddr_in server_addr;rn struct sockaddr_in client_addr;rn int err;rn pid_t pid;rn ss=socket(AF_INET,SOCK_STREAM,0);rn if(ss<0)rn rn printf("socket error\n");rn return -1;rn rn bzero(&server_addr,sizeof(server_addr));//清零rn server_addr.sin_family=AF_INET;rn server_addr.sin_addr.s_addr=htonl(INADDR_ANY);rn server_addr.sin_port=htons(PORT);rn err=bind(ss,(struct sockaddr*)&server_addr,sizeof(server_addr));rn if(err<0)rn rn printf("bind error\n");rn return -1;rn rn err=listen(ss,BACKLOG);rn if(err<0)rn rn printf("listen error\n");rn return -1;rn rn for(; ;)rn rn int addrlen=sizeof(struct sockaddr);rn sc=accept(ss,(struct sockaddr *)&client_addr,&addrlen);rn if(sc<0)rn rn continue;rn rn pid=fork();rn if(pid==0)rn rn close(ss);rn process_conn_server(sc);rn rn elsern rn close(ss);rn rn rn rnrnvoid process_conn_server(int s)rnrn ssize_t size=0;rn char buffer[1024];rn for(; ;)rn rn size=read(s,buffer,1024);rn if(size==0)rn rn return;rn rn sprintf(buffer,"%d bytes altogether \n",size);rn write(s,buffer,strlen(buffer)+1);rn rnrnrn[/code]rn这是客户端程序,出现问题的就是这里,在linux里面,server端能运行起来,但是客户端的就是出现这个错误,求帮助!rn[code=C/C++]rn#include rn#includern#includern#includern#includern#includern#includern#includern//#includern#define PORT 8888rnvoid process_conn_server(int s);rnint main(int argc, char *argv[])rnrn int s;rn struct sockaddr_in server_addr;rn int err;rn int tmp=0;rn s=socket(AF_INET,SOCK_STREAM,0);rn if(s<0)rn rn printf("socket error\n");rn return -1;rn rn bzero(&server_addr,sizeof(server_addr));rn server_addr.sin_family=AF_INET;rn server_addr.sin_addr.s_addr=htonl(INADDR_ANY);rn tmp=server_addr.sin_port=htons(PORT);rn rn assert(tmp>0);rn rn printf("yes yes");rn rn tmp=0;rn tmp=inet_pton(AF_INET,argv[1],&(server_addr.sin_addr));rnrn assert(tmp>0);rn rn printf("yes");rn rn connect(s,(struct sockaddr *)&server_addr,sizeof(struct sockaddr));rn process_conn_server(s);rn close(s);rn rnvoid process_conn_server(int s)rnrn ssize_t size=0;rn char buffer[1024];rn for(; ;)rn rn size=read(0,buffer,1024);rn if(size>0)rn rn write(s,buffer,size);rn size=read(s,buffer,1024);rn write(1,buffer,size);rn rn rnrnrn谢谢了。。。。rn[/code]
Segmentation fault (core dumped)
[code=c]#include rn#include rn//#include rn#include rnusing namespace std;rnstruct userdevicernrn /* data */rn string m_devicename;rn long m_deviced;rn int m_devicePopedom;rn;rnrntypedef multimap USERTABLE;rntypedef USERTABLE::const_iterator CIT;rntypedef pair Range;rnint main()rnrn CIT it;rnuserdevice d1,d2,d3,d4;rnd1.m_devicename="d1";rnd1.m_deviced=12341234;rnd1.m_devicePopedom=123;rnrnd2.m_devicename="d2";rnd2.m_deviced=23622344;rnd2.m_devicePopedom=234;rnrnrnd3.m_devicename="d3";rnd3.m_deviced=23451234;rnd3.m_devicePopedom=345;rnrnrnd4.m_devicename="d4";rnd4.m_deviced=43622344;rnd4.m_devicePopedom=456;rnrnUSERTABLE m_user;rnm_user.insert(pair ("zhangsanfeng",d1));rnm_user.insert(pair ("zhangsanfeng",d2));rnm_user.insert(pair ("zhangsanfeng",d3));rnm_user.insert(pair ("zhangsanfeng",d4));rnrnRange range=m_user.equal_range("zhangsanfeng");rncout<first<<' ';rncout<second.m_devicename<first<<' ';rncout<second.m_devicename<second.m_deviced<<','rn <second.m_devicename.c_str()<<','rn <second.m_devicePopedom<first<<' ';就是这句,但是不知道为什么会出错啊,求高手指点啊
线程报错,Segmentation fault
void CDataOpEngine::run(void)rn LOG4CXX_DEBUG(logger, "CDataOpEngine::run(void) in!");rn CJob* job;rn CExtCmd* pEC;rn CJobParam *param;rn while(1)rn pEC=this->coServer->popExtCmf();rnrnrn if(!pEC)rn LOG4CXX_DEBUG(logger, "pEC is null");rn continue;rn rn if(!pEC->content)rn LOG4CXX_DEBUG(logger, "pEC->content is null");rn continue;rn rnrn param =new CJobParam();rnrn param->data.ec=pEC;rnrn param->svr.pComSvr=this->coServer;rn LOG4CXX_DEBUG(logger, "CDataOpEngine::run(void) in!37-3");rn char cmdType=pEC->content[5];rn LOG4CXX_DEBUG(logger, "CDataOpEngine::run(void) in!43");rnrn if(cmdType =='0')rnrn job=new CComSvrLoginJob();rn rn else if(cmdType=='1')rnrn job=new CComSvrLogoutJob();rn rn elsernrn job=new CComSvrECOpJob();rnrn rn job->param=param;rnrn pool->addJob(job);rn rn cout<<"CDataOpEngine::run(void) out"<content[5]; 这一句时,时不时的报“Segmentation fault“错误,然后程序就停止了,请大家给分析一下原因,谢谢rn
数据结构-队列,Segmentation fault
#includern#includern#define SIZE 13rntypedef structrn int *base;rn int front;rn int rear;rn SqQueue;rnint InitQueue(SqQueue Q)rn Q.base=(int *)malloc(sizeof(int)*SIZE);rn if(!Q.base)exit(0);rn Q.front=Q.rear=0;rn return 1;rnrnint QueueLength(SqQueue Q)rn if(Q.rear=Q.front)exit(0);rn printf("The Length of Queue is %d\n",(Q.rear-Q.front+SIZE)%SIZE);rnrnvoid EnQueue(SqQueue Q,int e)rn if(((Q.rear+1)%SIZE)==Q.front)rn printf("full\n");rn exit(0);rn rn Q.base[Q.rear]=e;rn Q.rear=(Q.rear+1)%SIZE;rnrnvoid DeQueue(SqQueue Q,int e)rn if(Q.rear=Q.front)rn printf("empty\n");rn rn e=Q.base[Q.front];rn Q.front++;rnrnvoid Show(SqQueue Q,int i)rn printf("Num.%d is %d\n",i,Q.base[i]);rnrnint DestoryQueue(SqQueue Q)rn free(Q.base);rn Q.front=Q.rear=0;rn return 1;rnrnmain()rnrn int i,e;rn SqQueue Q;rn InitQueue(Q);rn for(i=0;i
“segmentation fault”求助
[img=https://img-bbs.csdn.net/upload/201807/31/1532970815_229897.jpg][/img]rn通过以上程序,我希望算出输入的整数的和并输出。rn[img=https://img-bbs.csdn.net/upload/201807/31/1532970656_692431.jpg][/img]rn但输入2 3 7 8时,出现一个错误“segmentation fault”,我查了一下,得知该错误是由于我访问了不该访问的内存导致的,但是仍旧不太明白,请问这个错误具体在以上程序中是怎么回事呢?
linux下segmentation fault
写了一个练习题,是n皇后问题,但是只要当n>=4时就会报错,不知是什么问题rn[code=c]rn#includern#includernusing namespace std;rn int n;rn int* arr;rn int sum=0;rn bool place(int m)rn rn for(int i=0;i>n;rn arr=new int(n);//下标为第几个,值为横轴rn traceback(0);rn cout<
相关热词 c# login 居中 c# 考试软件 c# 自然语言分析 c# 分段读取文件 c# 泛型反射 c#打断点 c# 时间转多少秒 c# 线程函数加参数 c# modbus 读取 c#查询集合表