linux真实内存爆满,linux系统中内存爆满之后会如何?

在使用python写程序的时候,发现一个可以无限迭代的迭代器,从而可以直接将系统中的内存占满,那么占满之后会发生什么呢?

1、 创建无限迭代,生成列表,如下:

[root@python ~]# python

Python 2.7.11 (default, Mar 20 2016, 14:21:08)

[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import itertools

>>> r = map(lambda x :x*x,itertools.count(1))

2、监控使用命令vmstat

[root@python ~]# vmstat 1 -S m #每隔一秒采集一次信息,单位为Mb

3、系统使用情况如下

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----

r b swpd free buff cache si so bi bo in cs us sy id wa st

1 0 0 851 15 52 0 0 0 0 414 69 34 3 63 0 0

1 0 0 610 15 52 0 0 0 0 995 7 83 17 0 0 0

1 0 0 458 15 52 0 0 0 0 616 13 70 30 0 0 0

1 0 0 345 15 52 0 0 0 0 489 9 70 30 0 0 0

1 0 0 187 15 52 0 0 0 0 694 11 77 23 0 0 0

3 2 29 50 2 18 0 0 220 41400 1154 190 71 23 0 6 0

1 2 238 65 1 13 0 0 580 191392 1232 261 49 25 0 26 0

1 2 375 50 0 12 0 0 1720 134264 1360 284 64 25 0 11 0

0 3 452 50 0 11 0 0 768 75212 758 150 38 13 0 49 0

1 1 528 62 0 9 0 0 192 74668 972 134 52 18 0 30 0

1 1 700 50 0 9 0 0 0 167244 1084 150 55 23 0 22 0

0 3 767 50 0 9 0 0 0 66068 456 48 17 12 0 71 0

1 1 808 60 0 9 0 0 1652 39688 505 191 17 9 0 74 0

0 3 952 50 0 7 0 0 504 141228 1078 191 57 20 0 23 0

0 2 1068 58 0 7 0 0 288 113176 860 127 40 21 0 40 0

2 2 1136 50 0 7 0 0 1584 66656 939 279 46 17 0 37 0

0 4 1252 50 0 7 0 0 276 113460 679 90 31 14 0 55 0

0 6 1266 53 0 8 0 0 904 13332 267 116 8 4 0 88 0

1 0 1339 63 0 7 0 0 216 71196 957 116 43 19 0 38 0

0 2 1549 52 0 7 0 0 0 205896 1196 194 49 31 0 20 0

1 0 1666 71 0 6 0 0 0 114372 948 57 43 19 0 37 0

0 2 1799 51 0 5 0 0 0 130104 1101 214 57 24 0 20 0

1 1 1922 61 0 5 0 0 0 119856 1092 132 51 23 0 26 0

0 2 2002 50 0 5 0 0 0 77788 662 103 31 17 0 52 0

2 0 2093 51 0 5 0 0 32 89104 1054 257 49 25 0 26 0

0 2 16 990 0 1 0 0 3824 19836 786 1639 21 17 0 62 0     从上面可以看出,swap使用的越来越多,free的空间越来越少,到最后达到swap的最大值之后,开始恢复内存空间。

系统的内存如下:

[root@python ~]# free -m

total used free shared buffers cached

Mem: 996 64 932 0 1 10

-/+ buffers/cache: 52 943

Swap: 2015 14 2001

4、 结论

当内存使用太多,没有剩余的内存的时候,操作系统会直接将进程杀死,如下所示:

[root@python ~]# python

Python 2.7.11 (default, Mar 20 2016, 14:21:08)

[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import itertools

>>> r = map(lambda x :x*x,itertools.count(1))

Killed 最后一个killed表示杀死进程,开始回收空间。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值