linux结束处于Tl状态的进程,释放内存资源

原因是运行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
posted @ 2024-06-22 14:44  沙滩炒花蛤  阅读(87)  评论(0编辑  收藏  举报