Reputation: 7197
I want to see statistics of a small C program, but is a small program that begins and ends. (Not some program that is long time running). I want to improve this program in terms of access to memory, cache hits, context switches, and that sort of things.
The parameters in /proc/[pid]/status
are great, but I cannot find the way to see them after execution.
How can I see this file after the proccess has finished execution?
Upvotes: 6
Views: 4153
Reputation: 382970
Another silly workaround is to GDB it and make it stop at exit
(or any other point of interest):
gdb -ex start -ex 'b exit' -ex c -ex 'info inferior' hello.out
info inferior
gives the PID as mentioned at: How does one obtain the pid of the currently debugged process in gdb?
Num Description Connection Executable
* 1 process 275096 1 (native) /home/ciro/ello.out
and then in another terminal we can:
cat /proc/275096/status
Upvotes: 1
Reputation: 22415
Tossing this system()
call at the end of your program will print /proc/[pid]/status
to stdout at the very last moment before your program quits.
#include <stdlib.h>
int main() {
system("cat /proc/$PPID/status");
return 0;
}
+1 for external programs like valgrind
. You can trap your program's exit with debugging utils and check complete statistics without modifying the program.
Upvotes: 6
Reputation: 56089
/proc/$pid/
only exists while a process is running. If you really want to see it after the process finishes (and I don't see what you would get beyond VmPeak), you could copy it shortly before the process exits.
Upvotes: 1
Reputation: 26322
You can't. The proc filesystem is an interface to kernel data structures. Once the process is gone the associated information is gone too.
If you're looking to improve the performance and memory footprint of the application you may want to investigate valgrind and its friends like cachegrind.
Upvotes: 4