Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7583155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:36:52+00:00 2026-05-30T18:36:52+00:00

So, I do: $ ulimit -s 8192 Great. As I understand this, the stack

  • 0

So, I do:

$ ulimit -s
8192

Great. As I understand this, the stack segment of any process cannot exceed 8192 kilobytes.

Now, to challenge that..

#include <stdio.h>

void over_8k(void) {
    char buf[1024*1024*20];
}

int main(int argc, char** argv) {
    printf("Starting .. ");
    over_8k();
    printf(" finishing.\nHow did this work?\n");
    return 0;
}

Compiled. Ran. No problems. Well this isn’t right? over_8k alone should have a stack frame of, well, over 20 megabytes. Well, let’s try accessing those 20 million bytes:

#include <stdio.h>
#include <string.h>

void over_8k(void) {
    char buf[1024*1024*20];
    memset(buf, 'A', sizeof(buf));
}

int main(int argc, char** argv) {
    printf("Starting .. ");
    over_8k();
    printf(" finishing.\nHow did this work?\n");
    return 0;
}

.. drum roll ..

Segmentation fault: 11

Great. But that’s not the error I’d expect? Invalid memory access?

Why does it raise a segfault, and doesn’t error out earlier? On call to over_8k perhaps? How does this work? I want to know everything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:36:53+00:00Added an answer on May 30, 2026 at 6:36 pm

    Expanding on my comment…

    There’s two possibilities I can think of:

    The compiler is optimizing out the entire buf array:

    In MSVC, with optimizations enabled, the entire array is being completely optimized out and is not allocated at all. So it’s not using any stack.

    Stack allocation is just an increment/decrement to the stack pointer:

    sub rsp, 20971520
    

    won’t segfault. It’s just a pointer. It will only segfault when you try to access it into unmapped memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error in my program... mprotect: Cannot allocate memory ulimit -a
ulimit -s shows the default stack size limit . Is there a startup default
What is the relationship between ulimit -s <value > and the stack size (at
There are certain conditions that can cause stack overflows on an x86 Linux system:
I have the following script: cat > /tmp/script.sh <<EndOfScript #!/bin/sh ulimit -n 8192 run_app
According to the manpage, -l in ulimit means The maximum size that may be
I have some daemon processes that crashes every now and then and I want
I am using Fedora linux where ulimit -n 10000 increases file limit upto 10000.
The process running get stuck around 32 000 (± 5%) ~# cat /proc/sys/kernel/threads-max 127862
I recently ran into a bug with the linux stack and the linux stack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.