我有以下腳本:的Python閱讀Linux進程的內存和轉儲到文件
import sys, os
pid = sys.argv[1]
maps_file = open("/proc/%s/maps" % pid, 'r')
mem_file = open("/proc/%s/mem" % pid, 'r')
for line in maps_file.readlines(): # for each mapped region
m = re.match(r'([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])', line)
if m.group(3) == 'r': # if this is a readable region
start = int(m.group(1), 16)
end = int(m.group(2), 16)
mem_file.seek(start) # seek to region start
chunk = mem_file.read(end - start) # read region contents
#print chunk, # dump contents to standard output
mem_dump = open(pid+".bin", "wb")
mem_dump.write(str(chunk,))
mem_dump.close()
maps_file.close()
mem_file.close()
所有workds以及(傾銷進程的內存),但迄今爲止我無法保存數據到文件。我究竟做錯了什麼?
會發生什麼?你有錯誤嗎? – codebox
沒有錯誤,但沒有寫入任何文件: - | – bsteo