在linux vps,偶尔会出现错误bash: fork: Cannot allocate memory。这是vps的bug,虽然你可能还有很多内存没有用完。怎么办?最理想的办法就是重启vps,不想重启怎么办?看下面的操作过程:
[[email protected]]# more database.php
-bash: fork: Cannot allocate memory
[[email protected]]# free
-bash: fork: Cannot allocate memory
[[email protected]]# reboot
-bash: fork: Cannot allocate memory
[[email protected]]# service httpd stop
-bash: fork: Cannot allocate memory
[[email protected]]# service httpd stop
-bash: fork: Cannot allocate memory
[[email protected]]# service httpd stop
-bash: fork: Cannot allocate memory
[[email protected]]# service httpd stop
-bash: fork: Cannot allocate memory
[[email protected]]# service httpd stop
-bash: fork: Cannot allocate memory
[[email protected]]# top
-bash: fork: Cannot allocate memory
[[email protected]]# free
-bash: fork: Cannot allocate memory
连free命令都无法执行。reboot也无法执行。怎么办?等待几分钟再试一试。我等了3分钟,然后发现free可以用了。这时候别大意,全部重启一下apache/mysql等,这样就可以稳定一段时间了:
[[email protected]]# free
total used free shared buffers cached
Mem: 524800 245908 278892 0 0 0
-/+ buffers/cache: 245908 278892
Swap: 0 0 0
[[email protected]]# service httpd stop
Stopping httpd: [ OK ]
[[email protected]]# free
total used free shared buffers cached
Mem: 524800 81272 443528 0 0 0
-/+ buffers/cache: 81272 443528
Swap: 0 0 0
[[email protected]]# top
top - 11:27:04 up 11 days, 6:16, 2 users, load average: 1.53, 0.63, 0.48
Tasks: 20 total, 1 running, 19 sleeping, 0 stopped, 0 zombie
Cpu(s): 6.2%us, 0.6%sy, 0.0%ni, 88.1%id, 5.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 524800k total, 81656k used, 443144k free, 0k buffers