can someone explain why this "endless" loop segfaults quickly? For example, let's say we have this function:
#!/bin/bash
foo() {
foo
}; foo
This segfaults after 8-10 seconds. Examining via strace, we can see a lot of brk() calls:
brk(0x2e11000) = 0x2e11000
brk(0x2e12000) = 0x2e12000
brk(0x2e13000) = 0x2e13000
brk(0x2e14000) = 0x2e14000
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x7ffcddf5ff68} ---
+++ killed by SIGSEGV +++
Segmentation fault
My questions are:
- is this segfaulting because it's trying to access an unmapped region in memory space (via brk)?
- If yes, why is it trying to access it?
- Would malloc() be a better choice here?
- If you have any extra/trivia information on this, it would be appreciated.