I am using Centos 7.8 and further investigations shows that the problem occurs when
soft and hard limits are equal. In our case 157286400.
Lowering the softlimit will make ruby run without error.
I have made similar tes on Ffedora 36 and here the code runs without problems.
Se the following from Centos
cat /proc/self/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 157286400 157286400 bytes
Max core file size unlimited unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 688754 688754 processes
Max open files 32768 32768 files
Max locked memory unlimited unlimited bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 688754 688754 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
./ruby -h
Segmentation fault (core dumped)
ulimit -S -s 1572
./ruby -h
Usage: /home/projects/sysadmin/people/johnd/ruby/ruby [switches] [--] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument)
-a autosplit mode with -n or -p (splits $_ into $F)
-c check syntax only
-Cdirectory cd to directory before executing your script
-d set debugging flags (set $DEBUG to true)
-e 'command' one line of script. Several -e's allowed. Omit [programfile]
-Eex[:in] specify the default external and internal character encodings
-Fpattern split() pattern for autosplit (-a)
-i[extension] edit ARGV files in place (make backup if extension supplied)
-Idirectory specify $LOAD_PATH directory (may be used more than once)
-l enable line ending processing
-n assume 'while gets(); ... end' loop around your script
-p assume loop like -n but print line also like sed
-rlibrary require the library before executing your script
-s enable some switch parsing for switches after script name
-S look for the script using PATH environment variable
-v print the version number, then turn on verbose mode
-w turn warnings on for your script
-W[level=2|:category] set warning level; 0=silence, 1=medium, 2=verbose
-x[directory] strip off text before #!ruby line and perhaps cd to directory
--jit enable JIT for the platform, same as --mjit (experimental)
--mjit enable C compiler-based JIT compiler (experimental)
-h show this message, --help for more info
cat /proc/self/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 1609728 157286400 bytes
Max core file size unlimited unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 688754 688754 processes
Max open files 32768 32768 files
Max locked memory unlimited unlimited bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 688754 688754 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us