c언어에서 file open시 이상한 error!!

익명 사용자의 이미지

어떠한 file을 fopen을 사용하여 열어 작업을하고 닫는
프로그램이 있습니다.

그런데
잘 되다가 약 800번 이후로는 open이 되질 않는
기이한 현상이 발생하더군요..
그래서
다음과 같은 코드를 작성했습니다.

i=0;
while( (idFp = fopen("./index.out", "w")) == NULL) {
printf("index.out open error!! -- %d\n",i);
sleep(3);
if(i > 10 )
exit(-1);
i++;
}

이렇게 작성을 한후 다시 실행을 하니까
약 800번 이후부터

index.out open error!! -- 0
index.out open error!! -- 1
.
.
.
index.out open error!! -- 0
index.out open error!! -- 1
.
.

즉 위와 같이 2번의 open 실패 이후 file이 열리더군요...
위와 같은 error 는 계속 나와요...

처음부터 error가 나온다면 소스가 문제있다고 생각하지만
이건 어느정도 작업이 진행된 다음 error가 나니까
미치겠내요....

gcc버전은 2.91.66 이구요
리눅스 커널은 2.2.15 입니다.

고수님들의 조언 기다리겠습니다...

꼬릿말..
어떠한 시도도 해볼 의향이 있습니다.

file open을 수천번 하는 프로그램또 만들어 봤는데 이런적은
없었습니다....

익명 사용자의 이미지

좀더 자세한 에러 내용을 알아 보실려면 errno 변수를 사용하여

정확한 에러값을 알아봐야 할것 같습니다.

익명 사용자의 이미지

man errno
를 봐도
.h 파일과 선언만 나와 있내요..
그냥
extern int errno;
이렇게만 해두면
표시가 되는건지??
잘 안되내요...

꼬릿말..
답변 고맙습니다....

익명 사용자의 이미지

일단 errno.h 파일을 include 하신후

extern int errno 변수를 선언하시고 사용하시면 됩니다..

#include

extern int errno;

int main()
{
FILE *fp;

fp = fopen("temp", "r");
if ( fp == NULL )
{
printf("file open error errno = %d\n", errno);
exit(-1);
}

fclose(fp);
}

익명 사용자의 이미지

지금 막 그렇게 해서 컴파일 하고 다시 실행했습니다.
결과는 약 30분 정도 기달려야 나올것 같내요...
errno는 man page를 참조하면 될것 같구요....

결과 나오면 다시 글 올리죠... ^^;

익명 사용자의 이미지

위의 방법으로 test한 결과

errno 는 24번..

내용은 Too many open files

너무 많은 file을 열었다고 하내요..

님의 조언 덕분에 돌파구를 찾을수 있을것 같습니다.
감사합니다 ^.*

sun1226의 이미지

errno를 사용해서 정확한 에러내용을 파악하시길..

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.