최근 프로그래밍 도중 아주 이상한 현상을 경험했습니다.

chasin의 이미지

그림에 표현된 부분에서 파일을 아주 많이 읽고 닫고를 반복합니다. 물론 다 다른 파일입니다.
또한 동시에 수백 개를 여는 것은 아닙니다.

근데, 이 부분에서 파일 오픈 횟수가 489번째 되면 프로그램이 while 부분에서 아무런 메세지
출력없이 죽어버립니다.

그래서 제가 if(TFN>488)이란 구문을 일부러 넣었습니다. 488번째까지 이상없이 실행되는 것을 보면
이 함수 부분에서 별 다른 문제는 없어보입니다.

이 화일들외에 프로그램의 다른 부분에서 임시 파일 포함하여 대충 10개 정도 열려 있는 걸 포함하면
gcc에서 처리할 수 있는 파일 갯수에 제한이 있는 건가요?(동시에 오픈할 수 있는 파일 갯수가 아님)

동시에 오픈할 수 있는 파일 갯수는 헤드파일에서 변경하여 컴파일 할 정도는 됩니다.

대충 500개 정도가 limit(동시에 오픈할 수 있는 파일 갯수를 말하는 게 아님) 같은데, 확실히 알 수가 없네요.
Head file 찾아봐도 이런 변수는 정의된 게 없는 거 같고요.

혹시 이런 경험 하신 고수분 안계신가요? 한 수 지도 부탁드립니다.

     for(i=0;i<n_part;i++) {
                  if(PD[i].zflag==0&&PD[i].pc>=ms_pc&&PD[i].rflag==0) {
                            ++TFN;
                            fLN=max_s=lat_s=0;
                            memset(s,0,sizeof(s));
                            if((part=fopen(strcat(itoa(PD[i].pd,s,10),"_internal.cur"),"rt"))==0) {
                                                    printf("\n\n\aFile '%s' in %s not exists.",s,strcat(d,"/data"));
                                                    sTOP();
                            }
                            else part=fopen(strcat(itoa(PD[i].pd,s,10),"_internal.cur"),"rt");
 
                            if(TFN>488) {
                                         printf("\n\n\aMaximum number(488) of files which can be handled was reached !!!");
                                         printf("\nPlease increase value of mass percentage in .csv file !!!");
                                         sTOP();
                            }
                            else {
                                         while((fgets(str,MaxCN+1,part))!=NULL) { // file 489번째에서 파일은 열리지만 file size=0임
                                                   if(strspn(str,"* Maxval=")>=10) max_s=fLN;
                                                   if(strspn(str,"endcurve")==8)   lat_s=fLN;
                                                   fLN++;
                                         }
                            }
 
                            if(max_s==0||lat_s==0) {
                                                  printf("\n\n\aFile '%s' in %s looks corrupted !!!",s,strcat(d,"/data"));
                                                   printf("\nPlease check the file !!!");
                                                   sTOP();
                            }
                            else rewind(part);
 
                            for(j=0;j<max_s+1;j++) fgets(str,MaxCN+1,part);
                            sscanf(str,"%s %s %f %s %s %f",nu,nu,&PD[i].mi,nu,nu,&PD[i].ti);
                            for(j=0;j<lat_s-max_s-2;j++) fgets(str,MaxCN+1,part);
                            fscanf(part,"%f %f",&tim,&PD[i].li);
                            fclose(part);
 
                            data[a][i].mi=PD[i].mi;
                            data[a][i].li=PD[i].li;
                            data[a][i].ti=PD[i].ti;
                  }
     }
chasin의 이미지

gdb를 이용해서 debugging을 해보니

"warning : Invalid parameter passed to C runtime function."라는 메세지가 나오네요

이 메시제가 뭐 때문에 나온지 이해가 안되는군요.

planetarium의 이미지

                            if((part=fopen(strcat(itoa(PD[i].pd,s,10),"_internal.cur"),"rt"))==0) {
                                                    printf("\n\n\aFile '%s' in %s not exists.",s,strcat(d,"/data"));
                                                    sTOP();
                            }
                            else part=fopen(strcat(itoa(PD[i].pd,s,10),"_internal.cur"),"rt");

fopen() 을 두 번씩 하고 계시네요. 두개 열고 하나 닫고, 두개 열고 하나 닫고 하는군요.

chasin의 이미지

오옷... 문제가 해결됐습니다. 너무 감사합니다. 그럼 488번째까지는 왜 되었을까요? 아~~~ 넘 궁금합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.