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;
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
add a comment |
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
add a comment |
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
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
c linux stack heap
edited Mar 9 at 3:55
jww
54.2k41234515
54.2k41234515
asked Oct 19 '16 at 9:55
shim_mangshim_mang
77212
77212
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
You can get in the below file. You should be root user.
/proc/<pid>/maps
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
You can get in the below file. You should be root user.
/proc/<pid>/maps
add a comment |
You can get in the below file. You should be root user.
/proc/<pid>/maps
add a comment |
You can get in the below file. You should be root user.
/proc/<pid>/maps
You can get in the below file. You should be root user.
/proc/<pid>/maps
answered Oct 19 '16 at 11:37
Vijay S BVijay S B
717617
717617
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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