'How to see contents of /proc/[pid]/status after process finishes execution?
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?
Solution 1:[1]
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.
Solution 2:[2]
/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.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kristof Provost |
| Solution 2 | Kevin |
| Solution 3 | Ciro Santilli Путлер Капут å…四事 |
