Question on SIGSEGV / Stack growth

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi ,
 
I have a question regarding SIGSEGV in the context of process stack
growth. I have the 
following piece of code.
 
#include<stdio.h>
main()
{
    char *ptr;
    char i=10;
    int j;
    ptr = &i;
    for(j=0; j<3000; j++)
        printf("%d -- %d\n",j, *(ptr+j));
}
 
 
I was expecting that the program will get a SIGSEGV immediately after
the first iteration of the for loop, since that
address doesn't belong to the process address space. But it didn't
happen. Then I thought that the stack is allocated 
in terms of pages and hence thought that I'll get SIGSEGV after a PAGE
size. Even that didn't happen.
 
The program got SIGSEGV at different values of j on different OS. On
linux it occured at 1896. 
 
I looked at the getrlimit value of stack size. Even that didn't match
with the value where I got SIGSEGV.
 
Any idea what's happening ?
 
Thanks & Regards,
Satish
-
: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux