Get the size of heap and stack per process in Linuxmalloc() - Does it use brk() or mmap()How to find load relocation for a PIE binary?How to determine CPU and memory consumption from inside a process?What and where are the stack and heap?Which is faster: Stack allocation or Heap allocationImprove INSERT-per-second performance of SQLite?Program stack and heap, how do they work?Windows assembly heap and stack?Is there a function to set a process stack/heap memory allocation?Linux Stack SizesHow to find if a variable is allocated in stack or heap?Can a UNIX process cause its heap and stack to step on each other?

Weird behaviour when using querySelector

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

What is the meaning of "of trouble" in the following sentence?

Why do UK politicians seemingly ignore opinion polls on Brexit?

Need help identifying/translating a plaque in Tangier, Morocco

Divisibility of sum of multinomials

How would photo IDs work for shapeshifters?

Circuitry of TV splitters

Doomsday-clock for my fantasy planet

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

Information to fellow intern about Hiring?

Finding files for which a command fails

LM317 - Calculate dissipation due to voltage drop

Can Medicine checks be used, with decent rolls, to completely mitigate the risk of death from ongoing damage?

Should I join an office cleaning event for free?

What Brexit solution does the DUP want?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Set up public ip on server

Email Account under attack (really) - anything I can do?

Copycat chess is back

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Why does this relative pronoun not take the case of the noun it is referring to?

Why a const reference doesn't extend the life of temporary object passed via function?

What are these boxed doors outside store fronts in New York?



Get the size of heap and stack per process in Linux


malloc() - Does it use brk() or mmap()How to find load relocation for a PIE binary?How to determine CPU and memory consumption from inside a process?What and where are the stack and heap?Which is faster: Stack allocation or Heap allocationImprove INSERT-per-second performance of SQLite?Program stack and heap, how do they work?Windows assembly heap and stack?Is there a function to set a process stack/heap memory allocation?Linux Stack SizesHow to find if a variable is allocated in stack or heap?Can a UNIX process cause its heap and stack to step on each other?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I wanted to know the size of heap and stack per process in linux. Is there any way to find it?



I found out that sbrk(0) will give me the end of heap. But how can I find the start of heap to get the heap size?



Also on stack size is there any way to find the start of stack and current stack pointer address per process through any library calls or system calls?










share|improve this question






























    1















    I wanted to know the size of heap and stack per process in linux. Is there any way to find it?



    I found out that sbrk(0) will give me the end of heap. But how can I find the start of heap to get the heap size?



    Also on stack size is there any way to find the start of stack and current stack pointer address per process through any library calls or system calls?










    share|improve this question


























      1












      1








      1








      I wanted to know the size of heap and stack per process in linux. Is there any way to find it?



      I found out that sbrk(0) will give me the end of heap. But how can I find the start of heap to get the heap size?



      Also on stack size is there any way to find the start of stack and current stack pointer address per process through any library calls or system calls?










      share|improve this question
















      I wanted to know the size of heap and stack per process in linux. Is there any way to find it?



      I found out that sbrk(0) will give me the end of heap. But how can I find the start of heap to get the heap size?



      Also on stack size is there any way to find the start of stack and current stack pointer address per process through any library calls or system calls?







      c linux stack heap






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 at 3:55









      jww

      54.2k41234515




      54.2k41234515










      asked Oct 19 '16 at 9:55









      shim_mangshim_mang

      77212




      77212






















          2 Answers
          2






          active

          oldest

          votes


















          2














          On Linux, you can read /proc/[PID]/maps and find [heap] and [stack] entries.



          But for the GLIBC heap implementations usually used on Linux, the "heap" consists of both memory obtained via sbrk() that shows up in the /proc/[PID]/maps file as [heap] and memory obtained via mmap() - see this quesiton. So the "size" of the heap is going to be very hard to determine with certainty.



          And the region labelled [stack] in the maps file is the stack for the main thread only. Multithreaded processes will have multiple stacks, one for each thread. And they will show up in the maps file as anonymous memory - maybe. The application can control the memory used for a thread's stack via the use of pthread_attr_setstack() and set it to any memory the application might use.






          share|improve this answer

























          • Aren't there any system call to find out the stack and heap size?

            – shim_mang
            Oct 19 '16 at 12:46











          • @shim_mang The "system call"s used here are open(), read() and close() on /proc/PID/maps file.

            – Kamil Cuk
            Mar 9 at 7:00



















          1














          You can get in the below file. You should be root user.



           /proc/<pid>/maps 





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40127980%2fget-the-size-of-heap-and-stack-per-process-in-linux%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            On Linux, you can read /proc/[PID]/maps and find [heap] and [stack] entries.



            But for the GLIBC heap implementations usually used on Linux, the "heap" consists of both memory obtained via sbrk() that shows up in the /proc/[PID]/maps file as [heap] and memory obtained via mmap() - see this quesiton. So the "size" of the heap is going to be very hard to determine with certainty.



            And the region labelled [stack] in the maps file is the stack for the main thread only. Multithreaded processes will have multiple stacks, one for each thread. And they will show up in the maps file as anonymous memory - maybe. The application can control the memory used for a thread's stack via the use of pthread_attr_setstack() and set it to any memory the application might use.






            share|improve this answer

























            • Aren't there any system call to find out the stack and heap size?

              – shim_mang
              Oct 19 '16 at 12:46











            • @shim_mang The "system call"s used here are open(), read() and close() on /proc/PID/maps file.

              – Kamil Cuk
              Mar 9 at 7:00
















            2














            On Linux, you can read /proc/[PID]/maps and find [heap] and [stack] entries.



            But for the GLIBC heap implementations usually used on Linux, the "heap" consists of both memory obtained via sbrk() that shows up in the /proc/[PID]/maps file as [heap] and memory obtained via mmap() - see this quesiton. So the "size" of the heap is going to be very hard to determine with certainty.



            And the region labelled [stack] in the maps file is the stack for the main thread only. Multithreaded processes will have multiple stacks, one for each thread. And they will show up in the maps file as anonymous memory - maybe. The application can control the memory used for a thread's stack via the use of pthread_attr_setstack() and set it to any memory the application might use.






            share|improve this answer

























            • Aren't there any system call to find out the stack and heap size?

              – shim_mang
              Oct 19 '16 at 12:46











            • @shim_mang The "system call"s used here are open(), read() and close() on /proc/PID/maps file.

              – Kamil Cuk
              Mar 9 at 7:00














            2












            2








            2







            On Linux, you can read /proc/[PID]/maps and find [heap] and [stack] entries.



            But for the GLIBC heap implementations usually used on Linux, the "heap" consists of both memory obtained via sbrk() that shows up in the /proc/[PID]/maps file as [heap] and memory obtained via mmap() - see this quesiton. So the "size" of the heap is going to be very hard to determine with certainty.



            And the region labelled [stack] in the maps file is the stack for the main thread only. Multithreaded processes will have multiple stacks, one for each thread. And they will show up in the maps file as anonymous memory - maybe. The application can control the memory used for a thread's stack via the use of pthread_attr_setstack() and set it to any memory the application might use.






            share|improve this answer















            On Linux, you can read /proc/[PID]/maps and find [heap] and [stack] entries.



            But for the GLIBC heap implementations usually used on Linux, the "heap" consists of both memory obtained via sbrk() that shows up in the /proc/[PID]/maps file as [heap] and memory obtained via mmap() - see this quesiton. So the "size" of the heap is going to be very hard to determine with certainty.



            And the region labelled [stack] in the maps file is the stack for the main thread only. Multithreaded processes will have multiple stacks, one for each thread. And they will show up in the maps file as anonymous memory - maybe. The application can control the memory used for a thread's stack via the use of pthread_attr_setstack() and set it to any memory the application might use.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 23 '17 at 12:00









            Community

            11




            11










            answered Oct 19 '16 at 11:36









            Andrew HenleAndrew Henle

            20.7k31535




            20.7k31535












            • Aren't there any system call to find out the stack and heap size?

              – shim_mang
              Oct 19 '16 at 12:46











            • @shim_mang The "system call"s used here are open(), read() and close() on /proc/PID/maps file.

              – Kamil Cuk
              Mar 9 at 7:00


















            • Aren't there any system call to find out the stack and heap size?

              – shim_mang
              Oct 19 '16 at 12:46











            • @shim_mang The "system call"s used here are open(), read() and close() on /proc/PID/maps file.

              – Kamil Cuk
              Mar 9 at 7:00

















            Aren't there any system call to find out the stack and heap size?

            – shim_mang
            Oct 19 '16 at 12:46





            Aren't there any system call to find out the stack and heap size?

            – shim_mang
            Oct 19 '16 at 12:46













            @shim_mang The "system call"s used here are open(), read() and close() on /proc/PID/maps file.

            – Kamil Cuk
            Mar 9 at 7:00






            @shim_mang The "system call"s used here are open(), read() and close() on /proc/PID/maps file.

            – Kamil Cuk
            Mar 9 at 7:00














            1














            You can get in the below file. You should be root user.



             /proc/<pid>/maps 





            share|improve this answer



























              1














              You can get in the below file. You should be root user.



               /proc/<pid>/maps 





              share|improve this answer

























                1












                1








                1







                You can get in the below file. You should be root user.



                 /proc/<pid>/maps 





                share|improve this answer













                You can get in the below file. You should be root user.



                 /proc/<pid>/maps 






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Oct 19 '16 at 11:37









                Vijay S BVijay S B

                717617




                717617



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f40127980%2fget-the-size-of-heap-and-stack-per-process-in-linux%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme