Results 1 to 4 of 4
Hi guys, I'm stuck again with file I/O.
In my program, I made bunch of file access in one loop.
and when I run it, it runs good.
But once ...
- 04-08-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 7
File I/O error
Hi guys, I'm stuck again with file I/O.
In my program, I made bunch of file access in one loop.
and when I run it, it runs good.
But once a loop count gets 64, it suddenly can't get a permission to access a file. (I catch this error from error checking line after open function)
I can't show all of m codes because it's too nasty & long. So I put a kind of skeleton code.
int factor = 0;
while(1)
{
multiply("input", factor, "result");
factor++;
}
input & result is just simple text file where numbers that I'm using will be stored.
I have initial value in input (let's say in here 100, in fact my case it was 7179) and everything is running correctly.
multiply function code will look like follow
multiply(file1, factor, file2)
{
int f1, f2;
f1 = open(file1, 0);
error checking
f2 = open(file2, 0);
error checking
do multiply f1 by given factor
close(f1);
close(f2);
}
I really don't understand why I get error at 64th loop.
Any ideas?
Thanks in advance
- 04-08-2010 #2Linux Newbie
- Join Date
- Mar 2010
- Posts
- 121
1) When the call fails, what does perror() output?
2) There is a limit to the number of open file descriptors any one process can have - i doubt this is the problem, but check that your close() calls are completing correctly - a simple:
or something, and see if it prints anything out.Code:if (close(f1) == -1) perror("close()");
- 04-09-2010 #3
Ok, I tried the skeleton and did not get any failure on file open.
Just to be sure, you are not attempting to call multiply() recursively are you? That would result in "too many open files" error message.
- 04-10-2010 #4Just Joined!
- Join Date
- Mar 2010
- Posts
- 7
Thanks Graham and sixdrift, I just solved it.
It was because of one of functions used in multiply; it deosn't close file at all!!


Reply With Quote