c++ - 如何放大 'free memory'

标签 c++ ubuntu out-of-memory raspberry-pi3

我使用colcon工具构建fastRTPS源码,在构建过程中,终端会卡在那里,最后输出一些错误信息。

在构建代码之前,在一个终端中,我使用命令 'free -m' 来检查内存信息,当列 'free memory' 的值减少到非常小的时候。执行构建命令的另一个终端将卡在那里。应该是内存不够用,怎么解决?

Before build code:
        total    used    free    shared    buff/cache    available
Mem:    912     124    700        4          87        768
Swap:   0       0      0

The last time ‘free -m’ was executed:
        total    used    free    shared    buff/cache   available
Mem:    912      820     4        4          87         72
Swap:   0        0       0 
  • 一个终端错误信息:
ubuntu@raspberrypi:~/ros2_ws/src/eProsima/Fast-RTPS$ colcon build
Starting >>> fastrtps
[Processing: fastrtps]                            
[Processing: fastrtps]                                     
[Processing: fastrtps]                                       
[Processing: fastrtps]                                       
[Processing: fastrtps]                                       
--- stderr: fastrtps                                         
c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
make[2]: *** [src/cpp/CMakeFiles/fastrtps.dir/rtps/writer/StatefulWriter.cpp.o] Error 4
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [src/cpp/CMakeFiles/fastrtps.dir/all] Error 2
make: *** [all] Error 2
---
Failed   <<< fastrtps   [ Exited with code 2 ]
  • 其他终端报错信息:
[76834.368716]Out of memory: Kill process 21298(cclplus) score 233 or sacrifice child
[76834.406051]Killed process 21298(cclplus) total-vm:251188KB, anon-rss:217952KB, file-rss:0KB, shmem-rss:0KB

最佳答案

  1. 您可以随时重新启动构建过程并最终完成它。
  2. make[2]: *** Waiting for unfinished jobs....听起来你正在运行几个编译过程,尝试禁用它,删除 -j N来自 make命令,只留下一个编译线程。
  3. 获取内存为 4Gb 的 Pi4

启用 swap 没有帮助,你只是没有足够的内存,使用 swap 会让它爬行 20 分钟然后死掉,而不是死掉然后重新启动。


好的,回答评论中的一些问题。我不仅在看到 *** waiting for unfinished jobs 时怀疑并行编译,而且当我看到:

Starting >>> fastrtps
[Processing: fastrtps]
[Processing: fastrtps]
[Processing: fastrtps]
[Processing: fastrtps]
[Processing: fastrtps]

请检查您使用的构建系统,如何将并行编译限制为单个进程。

关于c++ - 如何放大 'free memory',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58480705/

相关文章:

linux - 如何通过linux终端在文本文件中创建一个名为sth的文件夹?

ubuntu - Jenkins "Console Output"几乎是空的

ubuntu - 将 .obj+.mtl 模型转换为具有顶点颜色信息的 .ply 格式

c# - 如何在 Windows Phone 8 中释放图像缓存/内存?

c++ - CMake:find_package 中的项目如何破坏程序?

c++ - 需要支持 OpenGL 的跨平台 GUI 工具包

python - 如何在大型文件系统中查找重复文件同时避免 MemoryError

java - StringBuilder.append() 中的 OutOfMemoryError 即使有足够的内存

c++ - 循环退出 vector 并出现错误进程已完成,退出代码为 -1073741819

c++ - 如果您不知道传递的方法的确切类,如何将方法传递给类