segmentation fault - What is the maximum size of stack segment that can be allocated to a process? -
#include<stdio.h> #include<stdlib.h> void start(){ double xyz[135168]; char str[20]; xyz[0] = 1.2; sprintf(str,"pmap %d",getpid()); system(str); start(); } int main(){ char str[20]; sprintf(str,"pmap %d",getpid()); system(str); printf("entering start()\n"); start(); return 0; }
output
anirudh@anirudh-aspire-5920:~/desktop/testing$ ./a.out 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bfe1c000 132k rw--- [ stack ] total 1676k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bfd32000 1068k rw--- [ stack ] total 2612k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bfc2a000 2124k rw--- [ stack ] total 3668k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bfb22000 3180k rw--- [ stack ] total 4724k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bfa1a000 4236k rw--- [ stack ] total 5780k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bf911000 5296k rw--- [ stack ] total 6840k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bf809000 6352k rw--- [ stack ] total 7896k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bf701000 7408k rw--- [ stack ] total 8952k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bf5f9000 8464k rw--- [ stack ] total 10008k 3695: ./a.out 00110000 1372k r-x-- /lib/libc-2.12.1.so 00267000 8k r---- /lib/libc-2.12.1.so 00269000 4k rw--- /lib/libc-2.12.1.so 0026a000 12k rw--- [ anon ] 00b64000 4k r-x-- [ anon ] 00c27000 112k r-x-- /lib/ld-2.12.1.so 00c43000 4k r---- /lib/ld-2.12.1.so 00c44000 4k rw--- /lib/ld-2.12.1.so 08048000 4k r-x-- /home/anirudh/desktop/testing/a.out 08049000 4k r---- /home/anirudh/desktop/testing/a.out 0804a000 4k rw--- /home/anirudh/desktop/testing/a.out b78eb000 4k rw--- [ anon ] b78fe000 8k rw--- [ anon ] bf4f1000 9520k rw--- [ stack ] total 11064k segmentation fault
just before code crashed total memory allocated 9520k
. everytime run different values, of them in range of 9000k - 10000k
want know maximum size of stack segment can allocated process in linux.
another thing noticed
bfe1c000 132k rw--- [ stack ] . bf911000 5296k rw--- [ stack ] . bf4f1000 9520k rw--- [ stack ]
so each time virtual address of stack segment changes. every time new memory allocated , content old memory copy-pasted new memory location.
ulimit -s
should show maximum stack size.
Comments
Post a Comment