執行中程序的記憶體洩露

2021-08-01 10:43:24 字數 2183 閱讀 5641

pmap

pmap -d

其中的10240是執行緒的堆疊,

pmap |grep 10240|wc 

應該和執行緒數一致,如果不一致,可能是有執行緒異常退出、或有執行緒退出時沒有釋放資源,或者有執行緒沒啟動。

找到可疑的記憶體塊後,可以用gdb -p掛上程序,然後x/40a 0xaddr檢視對應記憶體的資料

[root@localhost security]# pmap -d 4993

4993: -bash

08047000 596 r-x-- 0000000000000000 003:00006 bash bash的**段

080dc000 28 rwx-- 0000000000094000 003:00006 bash bash的資料段

080e3000 280 rwx-- 00000000080e3000 000:00000 [ anon ] bash的堆

4d575000 84 r-x-- 0000000000000000 003:00006 ld-2.3.4.so 共享庫的**段

4d58a000 4 r-x-- 0000000000015000 003:00006 ld-2.3.4.so 共享庫的資料段

4d58b000 4 rwx-- 0000000000016000 003:00006 ld-2.3.4.so 共享庫的堆

4d58e000 1164 r-x-- 0000000000000000 003:00006 libc-2.3.4.so

4d6b1000 4 r-x-- 0000000000123000 003:00006 libc-2.3.4.so

4d6b2000 12 rwx-- 0000000000124000 003:00006 libc-2.3.4.so

4d6b5000 8 rwx-- 000000004d6b5000 000:00000 [ anon ] 匿名物理記憶體,

4d6de000 8 r-x-- 0000000000000000 003:00006 libdl-2.3.4.so

4d6e0000 8 rwx-- 0000000000001000 003:00006 libdl-2.3.4.so

4d807000 12 r-x-- 0000000000000000 003:00006 libtermcap.so.2.0.8

4d80a000 4 rwx-- 0000000000002000 003:00006 libtermcap.so.2.0.8

b7bc2000 176 r-x-- 0000000000000000 003:00006 gb18030.so

b7bee000 8 rwx-- 000000000002b000 003:00006 gb18030.so

b7bf0000 24 r-xs- 0000000000000000 003:00006 gconv-modules.cache

b7bf6000 1060 r-x-- 0000000002197000 003:00006 locale-archive

b7cff000 2048 r-x-- 0000000000000000 003:00006 locale-archive

b7eff000 36 r-x-- 0000000000000000 003:00006 libnss_files-2.3.4.so

b7f08000 8 rwx-- 0000000000008000 003:00006 libnss_files-2.3.4.so

b7f0a000 8 rwx-- 00000000b7f0a000 000:00000 [ anon ]

b7f20000 8 rwx-- 00000000b7f20000 000:00000 [ anon ]

bff0d000 84 rw--- 00000000bff0d000 000:00000 [ stack ]

ffffe000 4 ----- 0000000000000000 000:00000 [ anon ]

每列的含義如下:

引數 解釋

address:00378000-0038d000 程序所佔的位址空間

kbytes 該虛擬段的大小

rss 裝置號(主裝置:次裝置)

anon 裝置的節點號,0表示沒有節點與記憶體相對應

mode 許可權:r=read, w=write, x=execute, s=shared, p=private(copy on write)

linux中程序後台執行的方法

參考自 linux 讓程式在後台執行 有些程式我們在開啟時,會一直占用我們的終端,而且終端還不能關掉,所以這時候我們就需要讓程式在後台執行。1.命令 nohup nohup python u run.py run.log 2 1 引數說明 run.py 你需要後台執行的程式 run.log 執行的日...

linux中程序執行exec家族

啟動程序 exec族 共用標頭檔案 include int execl const char path,const char arg,int execlp const char file,const char arg,int execle const char path,const char arg...

linux執行中程序和執行緒分析

一.首先檢視系統中各程序占用cpu和記憶體的資訊,找出占用資源最多的程序pid。1.用top 獲得程序的動態更新 命令檢視 預設每5秒重新整理一次,按照cpu使用率排行。輸入m可以按照記憶體占用排行。查出占用cpu或記憶體比較高的程序pid。2.用ps 獲得程序的當前快照 命令。查出占用cpu或記憶...