Skip to content

Instantly share code, notes, and snippets.

@baudehlo
Created January 31, 2014 21:14
Show Gist options
  • Save baudehlo/8743285 to your computer and use it in GitHub Desktop.
Save baudehlo/8743285 to your computer and use it in GitHub Desktop.
Run this with ulimit -n 20, it works and has /etc/passwd open 100 times. Run with ulimit -n 10 and it will fail (due to stdio being open already).
#!/usr/bin/perl -w
for (1..10) {
fork or open_files()
}
exit();
sub open_files {
my @files = ();
for (1..10) {
open(my $fh, "/etc/passwd") or die "Unable to open: $!";
push @files, $fh;
}
print("Files: @files\n");
system("lsof -p $$");
sleep();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment