关于句柄泄漏的检察方法

关于句柄泄漏的检查方法
ubuntu我写了一个C程序,对大量文件进行处理以及数学计算.
在少量文件测试下可以,但是有大量数据频繁处理出现errno=24.(200个文件夹下有不定量txt文件)
我检查fopen\fclose和opendir\closedir,应该没有错误.
我猜测是不是句柄不够.
所以用FILE 用作全局变量,可是还是error24.
我希望尽量不扩大句柄数量.

所以想要进行以下关于文件使用句柄的测试,测试是否是句柄泄漏,但是我水平太弱.不知道怎么处理??????
希望大家帮帮忙!非常谢谢!!!!
------解决思路----------------------
from the errno, it's probably because your program opened too many files. The default number is 1024. It's normal for a lot programs that requires opening more than 1024 files.

You could do this in the shell that executes your program

#ulimit -n 2048

to double the limit or whatever value you want.

check the /etc/limits.conf to find out the maximum value you could set on Linux.
------解决思路----------------------
。。。
打开一个,读取数据,关掉。
打开一个,读取数据,关掉。
打开一个,读取数据,关掉。
打开一个,读取数据,关掉。
。。。
读取完成,开始计算。。。。
是这样操作的吗?
如果是这样操作的话应该不会有什么问题,除非你没关掉
------解决思路----------------------
lsof检查正在打开的句柄,此外linux的句柄数的上限也是可以设置的。
------解决思路----------------------
ulimit -a看一下file no限制了几个,然后封装一下fopen/fclose做一个计数统计,定时打印出来看看。
------解决思路----------------------
open files                      (-n) 1024