对于linux 程序内存的使用量

简介

如何查看一个linux程序是否产生内存泄露了呢??
可以使用valgrind

一般的命令是 valgrind --leak-check=full --show-reachable=yes --trace-children= yes ./a

执行结果

==771938== Memcheck, a memory error detector
==771938== Copyright (C) 2002-2017, and GNU GPL‘d, by Julian Seward et al.
==771938== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==771938== Command: ./a
==771938== 
0 : 496
[DEBUG] read finish ; ) 
[DEBUG] write finish ; ) 
==771938== 
==771938== HEAP SUMMARY:
==771938==     in use at exit: 0 bytes in 0 blocks
==771938==   total heap usage: 102,200 allocs, 102,200 frees, 5,431,706 bytes allocated
==771938== 
==771938== All heap blocks were freed -- no leaks are possible // 没有泄露
==771938== 
==771938== For lists of detected and suppressed errors, rerun with: -s
==771938== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

参考链接

https://blog.csdn.net/andylauren/article/details/93189740

/usr/bin/time -v ./a

/usr/bin/time -v ./a
0 : 496
[DEBUG] read finish ; ) 
[DEBUG] write finish ; ) 
        Command being timed: "./a"
        User time (seconds): 0.06
        System time (seconds): 0.01
        Percent of CPU this job got: 77%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.10
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 6636
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 872
        Voluntary context switches: 3731
        Involuntary context switches: 0
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

对于linux 程序内存的使用量

上一篇:C# web api返回类型设置为json的两种方法


下一篇:使用UNetbootin进行双系统安装 已经安装了win7 usb安装cent