Skip to content

Instantly share code, notes, and snippets.

@shvchk
Last active August 29, 2023 21:22
Show Gist options
  • Save shvchk/237a74cc9e46f1aff096ecfb508da06a to your computer and use it in GitHub Desktop.
Save shvchk/237a74cc9e46f1aff096ecfb508da06a to your computer and use it in GitHub Desktop.
Test max open files limit, `ulimit -n` | Source: https://stackoverflow.com/a/68895690
#!/usr/bin/env bash
case $BASH_VERSION in
''|[1-3].*|4.0.*) echo "ERROR: Bash 4.1 or newer required" >&2; exit 1;;
esac
[[ $1 ]] || { echo "Usage: $0 number-of-files" >&2; exit 1; }
echo "Running as process $$" >&2
for ((i=0; i<$1; i++)); do
exec {fd_num}>/dev/null || {
echo "Error on iteration $((i+1))" >&2
break
}
done
# if started from a TTY, let user press enter to exit
if [[ -t 0 ]]; then
read -p "Press enter to exit this process:" _
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment