vi fopentestcase.c
#include
#include
#define NoOfFILES 65536
int main()
{
char filename[10];
FILE *fds[NoOfFILES];
int i;
for (i = 0; i < NoOfFILES; ++i)
{
sprintf (filename, "/tmp/%d.log", i);
fds[i] = fopen(filename, "w");
if (fds[i] == NULL)
{
printf("\nNumber of open files = %d. " \
"fopen() failed with error: ", i);
perror("");
exit(1);
}
else
{
fprintf (fds[i], "some string");
}
}
return (0);
}
/usr/local/bin/gcc -o fopentestcase fopentestcase.c
$ ./fopentestcase
Number of open files = 253. fopen() failed with error: Too many open files
$
It errors out on the 254th file. This is because it is a 32 bit program.
No comments:
Post a Comment