title: Reading living process memory without interrupting it
body: <p>I would like to explore the memory of a living process, and when I do so, the process must not get disturbed - so attaching gdb to the process (which would stop it) is not an option.
  Therefore I would like to get this info from /proc/kcore (if you know of another way to do this please let me know).
  So I made a little experiment. I created a file called TEST with only "EXTRATESTEXTRA" inside.
  Then I opened it with less</p>
  
  <pre><code>$ less TEST
  </code></pre>
  
  <p>I got the PID of this process with</p>
  
  <pre><code>$ ps aux | grep TEST
  user    7785  0.0  0.0  17944   992 pts/8    S+   16:15   0:00 less TEST
  user    7798  0.0  0.0  13584   904 pts/9    S+   16:16   0:00 grep TEST
  </code></pre>
  
  <p>And then I used this script to create a dump of all files :</p>
  
  <pre><code>#!/bin/bash
  grep rw-p /proc/$1/maps | sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1 \2/p' | while read start stop; do gdb --batch --pid $1 -ex "dump memory $1-$start-$stop.dump 0x$start 0x$stop"; done
  </code></pre>
  
  <p>(I found it on this site <a href="https://serverfault.com/questions/173999/dump-a-linux-processs-memory-to-file">https://serverfault.com/questions/173999/dump-a-linux-processs-memory-to-file</a>)</p>
  
  <pre><code>$ sudo ./dump_all_pid_memory.sh 7785
  </code></pre>
  
  <p>After this, I looked for "TRATESTEX" in all dumped files :</p>
  
  <pre><code>$ grep -a -o -e '...TRATESTEX...' ./*.dump
  ./7785-00624000-00628000.dump:HEXTRATESTEXTRA
  ./7785-00b8f000-00bb0000.dump:EXTRATESTEXTRA
  ./7785-00b8f000-00bb0000.dump:EXTRATESTEXTRA
  </code></pre>
  
  <p>So I concluded that there must be an occurance of this string somewhere between 0x00624000 and 0x00628000 .
  Therefore I converted the offsets into decimal numbers and used dd to get the memory from /proc/kcore :</p>
  
  <pre><code>$ sudo dd if="/proc/kcore" of="./y.txt" skip="0" count="1638400" bs=1
  </code></pre>
  
  <p>To my surprise, the file y.txt was full of zeros (I didn't find the string I was looking for in it).</p>
  
  <p>As a bonus surprise, I ran a simmilar test at the same time with a different test file and found that the other test string i was using 
  (both processes with less were running at the same time) should be found at the same location (the dumping and greping gave the same offset).
  So there must be something I don't understand clearly.</p>
  
  <ul>
  <li><p>Isn't the /proc/pid/maps supposed to show the offset of the memory (i.e. : if it would say "XXX" is at offset 0x10, another program could not be using the same offset am I right? - this is the source of my second surprise)</p></li>
  <li><p>How can I read /proc/kmap to get the memory that belongs to a process which's pid I know ?</p></li>
  </ul>