Results 1 to 5 of 5
i have a program which communicates with another file to get info from a config file periodically, the other file checks ever 5 seconds if the file has changed...this one ...
- 11-05-2008 #1Just Joined!
- Join Date
- Dec 2006
- Posts
- 85
"too many open files"
i have a program which communicates with another file to get info from a config file periodically, the other file checks ever 5 seconds if the file has changed...this one opens the file and reads it, and writes its data (it only reads if the lockfile was created...this means the file has been changed (it used to work like a locfile thats why it has that name...now it just exists to tell tell you when a change has been made and read it...otherwise it just writes its data)
the problem is i keep getting this error saying "too many files open" and so it only reads it the first time the program runs...after that it errors...
included is the code for the function that is erroring...
Code:int fd,lockfile; if((lockfile=open("lock.dat",O_WRONLY|O_CREAT|O_EXCL))==-1) { printf("reading\n"); fd=open("data.dat",O_RDONLY); if(fd==-1) { perror("open"); } if(read(fd,&this->data,sizeof(wiimotedata))>0) { printf("button a is: %d\n",data.buttons.button_a); } close(fd); remove("lock.dat"); } else{ fd=open("data.dat",O_WRONLY); write(fd,&this->data,sizeof(wiimotedata)); close(fd); remove("lock.dat"); } }
- 11-05-2008 #2
As errors says you have opened too many files,
I think issue is with lockfile try and close it
If you want to know which file is opened try running strace with binary,close(lockfile)
example to trace open system calls ,
if u want to trace all system callsstrace -e trace=open ./a.out
HTHstrace -e trace=all./a.out- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 11-05-2008 #3
Lakshmipathi is correct on all counts. The only thing I would add is that this:
can also be said like this:Code:strace -e trace=all ./a.out
since the default for trace is all.Code:strace ./a.out
--
Bill
Old age and treachery will overcome youth and skill.
- 11-05-2008 #4Just Joined!
- Join Date
- Dec 2006
- Posts
- 85
oh wow...i deleted the file but didnt close it...*doh*
thanks i'll try it with closeing...
yeah that fixed it...cool thanks
- 11-06-2008 #5- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------


Reply With Quote
