Skip to content

Instantly share code, notes, and snippets.

@lasryaric
Created July 17, 2013 19:02
Show Gist options
  • Select an option

  • Save lasryaric/6023444 to your computer and use it in GitHub Desktop.

Select an option

Save lasryaric/6023444 to your computer and use it in GitHub Desktop.
fd.c file descriptor limit checker
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main()
{
int i = 0;
while (i < 66000) {
int fd = open("file.txt", O_RDONLY);
printf("fd = %d\n", fd);
if (fd == -1) {
return 0;
}
i++;
}
return 0;
}
@lasryaric
Copy link
Author

It may looks useless but it is actually very useful to check the number of authorized file descriptors to open in the current context.

cc fd.c && ./a,out

This will print the maximum number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment