“ 目录RHCA - 12 系统监控 - 33 valgrind命令检测内存泄漏 ”内存调试和性能分析工具常用于检测内存泄漏、非法内存访问、使用未初始化变量等语法格式valgrind [参数] 被检测命令此命令会降低被检测命令的运行速度10-50倍所以只用于调试参数作用--tool指定分析工具memcheck跟踪非法内存访问cachegrind分析缓存、性能helgrind检测多线程竞争、锁等问题--log-file将输出重定向到文件--v查看详细信息--vv查看更详细的信息--track-fdsyes跟踪文件描述符泄漏--suppressions文件名忽略指定规则文件中定义的错误--leak-checkfull查看详细的内存泄漏信息包括未释放的内存位置--track-originsyes查看未初始化变量的来源比如具体代码行回显结果definitely lost内存泄漏possibly lost可能泄漏例指针未置空still reachable程序结束时仍可达的内存通常是全局变量一、安装[rootwuzuniao ~]# yum -y install valgrind #安装调试软件二、使用[rootwuzuniao ~]# valgrind --leak-checkfull ls #检查是否有内存泄露3364 Memcheck, a memory error detector3364 Copyright (C) 2002-2013, and GNU GPLd, by Julian Seward et al.3364 Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info3364 Command: ls3364anaconda-ks.cfg a.txt cpuset Desktop Documents Downloads initial-setup-ks.cfg Music Pictures Public Templates Videos33643364 HEAP SUMMARY:3364 in use at exit: 22,693 bytes in 18 blocks3364 total heap usage: 52 allocs, 34 frees, 59,240 bytes allocated33643364 LEAK SUMMARY:3364 definitely lost: 0 bytes in 0 blocks3364 indirectly lost: 0 bytes in 0 blocks3364 possibly lost: 0 bytes in 0 blocks3364 still reachable: 22,693 bytes in 18 blocks3364 suppressed: 0 bytes in 0 blocks3364 Reachable blocks (those to which a pointer was found) are not shown.3364 To see them, rerun with: --leak-checkfull --show-leak-kindsall33643364 For counts of detected and suppressed errors, rerun with: -v3364 ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 3 from 3)[rootwuzuniao ~]#