linux結束處於Tl狀態的程序,釋放記憶體資源

沙滩炒花蛤發表於2024-06-22

原因是執行python結束時,用的ctrl+c不太行,嘗試Ctrl+z,發現有時候管用。後面htop一看記憶體似乎沒有釋放掉。

總結

針對處在 Tl 狀態的程序,用 kill 程序號 沒用,記憶體沒有釋放掉、程序沒有關掉。 用 kill -CONT 程序號 解決,原理是發現 SIGCONT 訊號,啟用程序,然後就可以關掉了,記憶體也釋放掉了

原因記錄

$ python main.py 
DEBUG init
environment arge :  {'map_name': 'jinan-1', 'seed': 6, 'thread_num': 15, 'eight_phase': True, 'min_action_time': 15, 'list_state_feature': ['cur_phase', 'lane_accumulate_waiting_time'], 'dic_reward_info': {'accumulate_waiting_time': -0.25}}
DEBUG SummaryWriter done
DEBUG Learner done
DEBUG Controller done
DEBUG Runner done
^C^Z
[1]+  Stopped                 python main.py

$ python main.py 
DEBUG init
environment arge :  {'map_name': 'jinan-1', 'seed': 6, 'thread_num': 15, 'eight_phase': True, 'min_action_time': 15, 'list_state_feature': ['cur_phase', 'lane_accumulate_waiting_time'], 'dic_reward_info': {'accumulate_waiting_time': -0.25}}
DEBUG Runner done
^C^Z
[2]+  Stopped                 python main.py

解決過程

$ ps aux | grep xiaomi | grep python # 查詢xiaomi的 python 程序
xiaomi  245450  108  0.1 13881632 1920968 pts/45 Sl+ 09:31 322:14 python train.py
xiaomi  403867 52.0 12.8 937281396 135541744 pts/202 Tl 14:25   1:06 python main.py
xiaomi  404726  136 16.5 937280492 175097972 pts/202 Tl 14:26   1:25 python main.py
xiaomi  405685  0.0  0.0  17688   648 pts/202  S+   14:27   0:00 grep --color=auto python

$ kill 403867

$ ps aux | grep xiaomi | grep python # 程序 403867 還在
xiaomi  245450  108  0.1 13881632 1920968 pts/45 Sl+ 09:31 322:32 python train.py
xiaomi  403867 46.2 12.8 937281396 135541744 pts/202 Tl 14:25   1:06 python main.py
xiaomi  404726  108 16.5 937280492 175097972 pts/202 Tl 14:26   1:25 python main.py
xiaomi  405904  0.0  0.0  17688   712 pts/202  S+   14:27   0:00 grep --color=auto python

$ kill 404726

$ ps aux | grep xiaomi | grep python
xiaomi  245450  108  0.1 13881632 1920968 pts/45 Rl+ 09:31 323:18 python train.py
xiaomi  403867 35.5 12.8 937281396 135541744 pts/202 Tl 14:25   1:06 python main.py
xiaomi  404726 70.4 16.5 937280492 175097972 pts/202 Tl 14:26   1:25 python main.py
xiaomi  406374  0.0  0.0  17688   708 pts/202  S+   14:28   0:00 grep --color=auto python

$ kill -CONT 404726
$ ps aux | grep xiaomi | grep python    # 程序 404726 已經關掉
[2]-  Terminated              python main.py
xiaomi  245450  108  0.1 13881376 1920712 pts/45 Rl+ 09:31 328:37 python train.py
xiaomi  403867 13.8 12.8 937281396 135541744 pts/202 Tl 14:25   1:06 python main.py
xiaomi  410292  0.0  0.0  17688   660 pts/202  S+   14:33   0:00 grep --color=auto python

$ kill -CONT 403867
$ ps aux | grep xiaomi | grep python
[1]+  Terminated              python main.py
xiaomi  245450  108  0.1 13879840 1919176 pts/45 Rl+ 09:31 332:42 python train.py
xiaomi  412742  0.0  0.0  17688   716 pts/202  S+   14:37   0:00 grep --color=auto python

相關文章