Skip to main content

One post tagged with "watch"

View All Tags

memory leak

· One min read

find memory leak of a running process

$ cat /proc/$pid/smaps
  1. find out the PID of the process
$ ps -aux
  1. capture /proc/PID/smaps and save into some file like before_meminc.txt
  2. wait till memory gets increased
  3. try again step 2
  4. find the difference between first smaps and 2nd smaps, e.g. with
$ diff -u before_meminc.txt after_meminc.txt
  1. note down the address range where memory got increased

  2. use pstack and watch command to get the right call stack

$ watch -n 1 'pstack $PID | tee -a $PID.stack'

C-c when we caputred right stack

  1. check our stack file, find the functions between address range which we got from step 6.