Dumping process memory

From Leo's Notes
Revision as of 17:21, 2 October 2022 by Leo (talk | contribs) (Created page with "Every Linux process has a pseudo <code>mem</code> device which can be used to read the process's memory pages. This mem file is found under <code>/proc/$pid/mem</code>. In order to properly use this file, you have to read the readable sections as outlined by its corresponding <code>maps</code> file. Simply <code>dd if=/proc/$pid/mem</code> would not work as you will end up reading invalid or non-readable pages, resulting in a <code>Input/output error</code>. Instead, y...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 2 October 2022, at 17:21.

Every Linux process has a pseudo mem device which can be used to read the process's memory pages. This mem file is found under /proc/$pid/mem. In order to properly use this file, you have to read the readable sections as outlined by its corresponding maps file.

Simply dd if=/proc/$pid/mem would not work as you will end up reading invalid or non-readable pages, resulting in a Input/output error. Instead, you should opt to use gdb to create a a core dump (using gcore $pid). On systems without gdb (think embedded systems), you may try to do this with the following bash-only solution.

Dumping process memory using Bash

# cat /proc/$pid/maps \