Linkers, Loaders & Executables
When recursion goes so deep that it exceeds the stack limit, what generally happens on Linux and similar systems?
- AIt touches a guard page beyond the stack where access is forbidden, and the program crashes
- BThe OS moves the stack to disk automatically, allowing unlimited depth
- COld stack frames are deleted automatically and the computation continues correctly
Show answer and explanation
Answer: A. It touches a guard page beyond the stack where access is forbidden, and the program crashes
The stack has a limit, and a guard page with access forbidden sits beyond it. When too-deep recursion pushes the stack into that page, a page fault occurs and the OS stops the program (a segmentation fault). The guard page's advantage is stopping the program before it corrupts other data. A large array as a local variable can cause the same thing, so large data is safer on the heap.
- A. Correct. It is detected as a stack overflow.
- B. The stack is not extended beyond its limit.
- C. Silently deleting frames would make returning impossible.