How to calculate the memory consumed by a “C” program in linux
I have written two C programmes
- one is using function pointer, and
- the other without function pointer.
Now i want to know the memory consumed by the two programmes , to see how memory can optimized.
memory performance cpu c optimization
add a comment |
I have written two C programmes
- one is using function pointer, and
- the other without function pointer.
Now i want to know the memory consumed by the two programmes , to see how memory can optimized.
memory performance cpu c optimization
add a comment |
I have written two C programmes
- one is using function pointer, and
- the other without function pointer.
Now i want to know the memory consumed by the two programmes , to see how memory can optimized.
memory performance cpu c optimization
I have written two C programmes
- one is using function pointer, and
- the other without function pointer.
Now i want to know the memory consumed by the two programmes , to see how memory can optimized.
memory performance cpu c optimization
memory performance cpu c optimization
edited Jun 3 '15 at 6:37
shivams
2,92611425
2,92611425
asked Jun 3 '15 at 6:07
NagrajNagraj
26112
26112
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
It would depend on what kind of stats you want, but if you're writing a program in C running on Linux, you'd definitely better know about Valgrind.
Valgrind can, not only profile detailed memory usage of your program, but also detect memory access violations which are common in C and possibly very hard to debug.
For your profiling purpose, take a look at docs about specific analysis tools, especially memcheck and massif.
add a comment |
If you are only interested in the memory used after the fact, then use GNU time
:
command time -v myprogram
(the above uses the bash
way of invoking the external time
command rather than the bash
builtin, your shell may vary).
Or, GNU memusage
:
memusage -T ./myprogram
If you are interested in the memory used on an ongoing basis (i.e. during a long running process), one of the other answers is probably better.
See also this related question: Memory usage command with syntax similar to the time command
add a comment |
Here's the resident set size and virtual memory size of all sshd processes on one system:
ulric@qvp2:~$ ps -eo rss,vsz,args|grep sshd|grep -v grep
448 55292 /usr/sbin/sshd -D
5176 147460 sshd: ulric [priv]
2776 149704 sshd: ulric@pts/3
Or perhaps easier:
ulric@qvp2:~$ ps aux|head -n 1&&ps aux|grep sshd|grep -v grep
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 13221 0.0 0.0 55292 448 ? Ss Apr21 0:01 /usr/sbin/sshd -D
root 16046 0.0 0.5 147460 5176 ? Ss 08:12 0:00 sshd: ulric [priv]
ulric 16187 0.0 0.2 149704 2776 ? S 08:12 0:00 sshd: ulric@pts/3
See the ps manpage for more options.
add a comment |
how can i know the memory consumption of my c coding..?
New contributor
add a comment |
The easiest to just catch the heap pointers through sbrk(0), cast them as 64-bit unsigned integers, and compute the difference after the memory gets allocated.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f207209%2fhow-to-calculate-the-memory-consumed-by-a-c-program-in-linux%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
It would depend on what kind of stats you want, but if you're writing a program in C running on Linux, you'd definitely better know about Valgrind.
Valgrind can, not only profile detailed memory usage of your program, but also detect memory access violations which are common in C and possibly very hard to debug.
For your profiling purpose, take a look at docs about specific analysis tools, especially memcheck and massif.
add a comment |
It would depend on what kind of stats you want, but if you're writing a program in C running on Linux, you'd definitely better know about Valgrind.
Valgrind can, not only profile detailed memory usage of your program, but also detect memory access violations which are common in C and possibly very hard to debug.
For your profiling purpose, take a look at docs about specific analysis tools, especially memcheck and massif.
add a comment |
It would depend on what kind of stats you want, but if you're writing a program in C running on Linux, you'd definitely better know about Valgrind.
Valgrind can, not only profile detailed memory usage of your program, but also detect memory access violations which are common in C and possibly very hard to debug.
For your profiling purpose, take a look at docs about specific analysis tools, especially memcheck and massif.
It would depend on what kind of stats you want, but if you're writing a program in C running on Linux, you'd definitely better know about Valgrind.
Valgrind can, not only profile detailed memory usage of your program, but also detect memory access violations which are common in C and possibly very hard to debug.
For your profiling purpose, take a look at docs about specific analysis tools, especially memcheck and massif.
answered Jun 3 '15 at 7:01
yaegashiyaegashi
8,35611734
8,35611734
add a comment |
add a comment |
If you are only interested in the memory used after the fact, then use GNU time
:
command time -v myprogram
(the above uses the bash
way of invoking the external time
command rather than the bash
builtin, your shell may vary).
Or, GNU memusage
:
memusage -T ./myprogram
If you are interested in the memory used on an ongoing basis (i.e. during a long running process), one of the other answers is probably better.
See also this related question: Memory usage command with syntax similar to the time command
add a comment |
If you are only interested in the memory used after the fact, then use GNU time
:
command time -v myprogram
(the above uses the bash
way of invoking the external time
command rather than the bash
builtin, your shell may vary).
Or, GNU memusage
:
memusage -T ./myprogram
If you are interested in the memory used on an ongoing basis (i.e. during a long running process), one of the other answers is probably better.
See also this related question: Memory usage command with syntax similar to the time command
add a comment |
If you are only interested in the memory used after the fact, then use GNU time
:
command time -v myprogram
(the above uses the bash
way of invoking the external time
command rather than the bash
builtin, your shell may vary).
Or, GNU memusage
:
memusage -T ./myprogram
If you are interested in the memory used on an ongoing basis (i.e. during a long running process), one of the other answers is probably better.
See also this related question: Memory usage command with syntax similar to the time command
If you are only interested in the memory used after the fact, then use GNU time
:
command time -v myprogram
(the above uses the bash
way of invoking the external time
command rather than the bash
builtin, your shell may vary).
Or, GNU memusage
:
memusage -T ./myprogram
If you are interested in the memory used on an ongoing basis (i.e. during a long running process), one of the other answers is probably better.
See also this related question: Memory usage command with syntax similar to the time command
edited Apr 13 '17 at 12:37
Community♦
1
1
answered Jun 3 '15 at 9:13
mr.spuraticmr.spuratic
6,9411128
6,9411128
add a comment |
add a comment |
Here's the resident set size and virtual memory size of all sshd processes on one system:
ulric@qvp2:~$ ps -eo rss,vsz,args|grep sshd|grep -v grep
448 55292 /usr/sbin/sshd -D
5176 147460 sshd: ulric [priv]
2776 149704 sshd: ulric@pts/3
Or perhaps easier:
ulric@qvp2:~$ ps aux|head -n 1&&ps aux|grep sshd|grep -v grep
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 13221 0.0 0.0 55292 448 ? Ss Apr21 0:01 /usr/sbin/sshd -D
root 16046 0.0 0.5 147460 5176 ? Ss 08:12 0:00 sshd: ulric [priv]
ulric 16187 0.0 0.2 149704 2776 ? S 08:12 0:00 sshd: ulric@pts/3
See the ps manpage for more options.
add a comment |
Here's the resident set size and virtual memory size of all sshd processes on one system:
ulric@qvp2:~$ ps -eo rss,vsz,args|grep sshd|grep -v grep
448 55292 /usr/sbin/sshd -D
5176 147460 sshd: ulric [priv]
2776 149704 sshd: ulric@pts/3
Or perhaps easier:
ulric@qvp2:~$ ps aux|head -n 1&&ps aux|grep sshd|grep -v grep
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 13221 0.0 0.0 55292 448 ? Ss Apr21 0:01 /usr/sbin/sshd -D
root 16046 0.0 0.5 147460 5176 ? Ss 08:12 0:00 sshd: ulric [priv]
ulric 16187 0.0 0.2 149704 2776 ? S 08:12 0:00 sshd: ulric@pts/3
See the ps manpage for more options.
add a comment |
Here's the resident set size and virtual memory size of all sshd processes on one system:
ulric@qvp2:~$ ps -eo rss,vsz,args|grep sshd|grep -v grep
448 55292 /usr/sbin/sshd -D
5176 147460 sshd: ulric [priv]
2776 149704 sshd: ulric@pts/3
Or perhaps easier:
ulric@qvp2:~$ ps aux|head -n 1&&ps aux|grep sshd|grep -v grep
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 13221 0.0 0.0 55292 448 ? Ss Apr21 0:01 /usr/sbin/sshd -D
root 16046 0.0 0.5 147460 5176 ? Ss 08:12 0:00 sshd: ulric [priv]
ulric 16187 0.0 0.2 149704 2776 ? S 08:12 0:00 sshd: ulric@pts/3
See the ps manpage for more options.
Here's the resident set size and virtual memory size of all sshd processes on one system:
ulric@qvp2:~$ ps -eo rss,vsz,args|grep sshd|grep -v grep
448 55292 /usr/sbin/sshd -D
5176 147460 sshd: ulric [priv]
2776 149704 sshd: ulric@pts/3
Or perhaps easier:
ulric@qvp2:~$ ps aux|head -n 1&&ps aux|grep sshd|grep -v grep
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 13221 0.0 0.0 55292 448 ? Ss Apr21 0:01 /usr/sbin/sshd -D
root 16046 0.0 0.5 147460 5176 ? Ss 08:12 0:00 sshd: ulric [priv]
ulric 16187 0.0 0.2 149704 2776 ? S 08:12 0:00 sshd: ulric@pts/3
See the ps manpage for more options.
answered Jun 3 '15 at 6:26
Ulric ErikssonUlric Eriksson
20416
20416
add a comment |
add a comment |
how can i know the memory consumption of my c coding..?
New contributor
add a comment |
how can i know the memory consumption of my c coding..?
New contributor
add a comment |
how can i know the memory consumption of my c coding..?
New contributor
how can i know the memory consumption of my c coding..?
New contributor
New contributor
answered 12 mins ago
kushalkushal
1
1
New contributor
New contributor
add a comment |
add a comment |
The easiest to just catch the heap pointers through sbrk(0), cast them as 64-bit unsigned integers, and compute the difference after the memory gets allocated.
add a comment |
The easiest to just catch the heap pointers through sbrk(0), cast them as 64-bit unsigned integers, and compute the difference after the memory gets allocated.
add a comment |
The easiest to just catch the heap pointers through sbrk(0), cast them as 64-bit unsigned integers, and compute the difference after the memory gets allocated.
The easiest to just catch the heap pointers through sbrk(0), cast them as 64-bit unsigned integers, and compute the difference after the memory gets allocated.
answered Apr 4 '17 at 15:13
Kakash1hatakeKakash1hatake
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f207209%2fhow-to-calculate-the-memory-consumed-by-a-c-program-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