C++和C程序内存占用对比分析
本例以简单程序为例,分析C++和C语言的内存占用情况。本运行环境为:
- Ubuntu 20.04 LTS
- G++/GCC version: 9.3.0
- libstdc++.so.6.0.28/libc-2.31.so
总结:
- 实现输出hello world功能,C++代码比C代码占用的内存要大很多,主要在于多链接了libgcc_s.so.1、libm-2.31.so、libstdc++.so.6.0.28三个库;
- 如果使用C++标准库中的container、vector等模板库,内存就更加可观了;
- 在嵌入式资源比较紧张的环境中,优先考虑使用C语言;
- 个人经验:C++比较适合开发大型程序,处理更加复杂的业务模型,扩展性和开发效率都比较好;
1,C代码文件为hello.c,C++代码文件为hello.cpp:
/* hello.c */ #include <stdio.h> #include <unistd.h> int main(void) { printf("hello world\n"); pause(); return 0x0; }
/* hello.cpp */ #include <iostream> #include <cstdlib> #include <unistd.h> int main(void) { std::cout << "hello world" << std::endl; pause(); return 0x0; }
2,编译
gcc hello.c -o c.out g++ hello.cpp -o cpp.out
3,可执行文件大小
从下面的表格中可以看到:
- C++编译之后的可执行文件,符号表的长度比C语言更多一些,strip之后可执行文件的size(占用的磁盘大小)是相同的;
- C++代码段比C语言大;
- Data相差不大(此例没有用到全局变量和静态变量),C++还是比C略大一些;
- BSS段相差比较大,说明C++有很多的全局变量/静态变量;
File Name | Size | Size(AfterStrip) | Text | Data | BSS |
c.out | 16728 | 14464 | 1653 | 608 | 8 |
cpp.out | 17352 | 14464 | 2543 | 672 | 280 |
Delta(C++ - C) | 624 | 0 | 890 | 64 | 272 |
xinpengc@xinpengc-VirtualBox:~/learn/cpp$ stat c.out cpp.out File: c.out Size: 14464 Blocks: 32 IO Block: 4096 regular file Device: 805h/2053d Inode: 928447 Links: 1 Access: (0775/-rwxrwxr-x) Uid: ( 1000/xinpengc) Gid: ( 1000/xinpengc) Access: 2020-08-09 22:03:44.245216821 +0800 Modify: 2020-08-09 22:03:36.333217100 +0800 Change: 2020-08-09 22:03:36.333217100 +0800 Birth: - File: cpp.out Size: 14464 Blocks: 32 IO Block: 4096 regular file Device: 805h/2053d Inode: 928442 Links: 1 Access: (0775/-rwxrwxr-x) Uid: ( 1000/xinpengc) Gid: ( 1000/xinpengc) Access: 2020-08-09 22:03:44.245216821 +0800 Modify: 2020-08-09 22:03:36.333217100 +0800 Change: 2020-08-09 22:03:36.333217100 +0800
xinpengc@xinpengc-VirtualBox:~/learn/cpp$ size c.out cpp.out
text data bss dec hex filename
1653 608 8 2269 8dd c.out
2543 672 280 3495 da7 cpp.out
4,运行时分析
在hello.cpp代码中,引入了pause,导致cpp.out链接了C标准库,所以内存使受到了C库的干扰,结果可能不是很准确:
(在下面第5小节中,去掉了pause,但C++代码还是链接了C标准库)
FileName | VmHWM (KB) | VmRSS (KB) | |
c.out | 580 | 580 | |
cpp.out | 1528 | 1528 | |
Delta | 948 | 948 |
xinpengc@xinpengc-VirtualBox:~/learn/cpp$ cat /proc/3340/status /proc/3340/maps Name: c.out Umask: 0002 State: S (sleeping) Tgid: 3340 Ngid: 0 Pid: 3340 PPid: 2112 TracerPid: 0 Uid: 1000 1000 1000 1000 Gid: 1000 1000 1000 1000 FDSize: 256 Groups: 4 24 27 30 46 120 131 132 1000 NStgid: 3340 NSpid: 3340 NSpgid: 3340 NSsid: 2112 VmPeak: 2488 kB VmSize: 2488 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 580 kB VmRSS: 580 kB RssAnon: 64 kB RssFile: 516 kB RssShmem: 0 kB VmData: 180 kB VmStk: 132 kB VmExe: 8 kB VmLib: 1644 kB VmPTE: 40 kB VmSwap: 0 kB HugetlbPages: 0 kB CoreDumping: 0 THP_enabled: 1 Threads: 1 SigQ: 0/7731 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 0000000000000000 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000003fffffffff CapAmb: 0000000000000000 NoNewPrivs: 0 Seccomp: 0 Speculation_Store_Bypass: vulnerable Cpus_allowed: 1 Cpus_allowed_list: 0 Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001 Mems_allowed_list: 0 voluntary_ctxt_switches: 1 nonvoluntary_ctxt_switches: 0 55d72012f000-55d720130000 r--p 00000000 08:05 928447 /home/xinpengc/learn/cpp/c.out 55d720130000-55d720131000 r-xp 00001000 08:05 928447 /home/xinpengc/learn/cpp/c.out 55d720131000-55d720132000 r--p 00002000 08:05 928447 /home/xinpengc/learn/cpp/c.out 55d720132000-55d720133000 r--p 00002000 08:05 928447 /home/xinpengc/learn/cpp/c.out 55d720133000-55d720134000 rw-p 00003000 08:05 928447 /home/xinpengc/learn/cpp/c.out 55d72027e000-55d72029f000 rw-p 00000000 00:00 0 [heap] 7fb897b56000-7fb897b7b000 r--p 00000000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7fb897b7b000-7fb897cf3000 r-xp 00025000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7fb897cf3000-7fb897d3d000 r--p 0019d000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7fb897d3d000-7fb897d3e000 ---p 001e7000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7fb897d3e000-7fb897d41000 r--p 001e7000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7fb897d41000-7fb897d44000 rw-p 001ea000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7fb897d44000-7fb897d4a000 rw-p 00000000 00:00 0 7fb897d5c000-7fb897d5d000 r--p 00000000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7fb897d5d000-7fb897d80000 r-xp 00001000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7fb897d80000-7fb897d88000 r--p 00024000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7fb897d89000-7fb897d8a000 r--p 0002c000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7fb897d8a000-7fb897d8b000 rw-p 0002d000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7fb897d8b000-7fb897d8c000 rw-p 00000000 00:00 0 7fffeb55d000-7fffeb57e000 rw-p 00000000 00:00 0 [stack] 7fffeb5ee000-7fffeb5f1000 r--p 00000000 00:00 0 [vvar] 7fffeb5f1000-7fffeb5f2000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] xinpengc@xinpengc-VirtualBox:~/learn/cpp$ xinpengc@xinpengc-VirtualBox:~/learn/cpp$ xinpengc@xinpengc-VirtualBox:~/learn/cpp$ cat /proc/3341/status /proc/3341/maps Name: cpp.out Umask: 0002 State: S (sleeping) Tgid: 3341 Ngid: 0 Pid: 3341 PPid: 2112 TracerPid: 0 Uid: 1000 1000 1000 1000 Gid: 1000 1000 1000 1000 FDSize: 256 Groups: 4 24 27 30 46 120 131 132 1000 NStgid: 3341 NSpid: 3341 NSpgid: 3341 NSsid: 2112 VmPeak: 5876 kB VmSize: 5876 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 1528 kB VmRSS: 1528 kB RssAnon: 156 kB RssFile: 1372 kB RssShmem: 0 kB VmData: 228 kB VmStk: 132 kB VmExe: 8 kB VmLib: 3344 kB VmPTE: 44 kB VmSwap: 0 kB HugetlbPages: 0 kB CoreDumping: 0 THP_enabled: 1 Threads: 1 SigQ: 0/7731 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000000000 SigCgt: 0000000000000000 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000003fffffffff CapAmb: 0000000000000000 NoNewPrivs: 0 Seccomp: 0 Speculation_Store_Bypass: vulnerable Cpus_allowed: 1 Cpus_allowed_list: 0 Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001 Mems_allowed_list: 0 voluntary_ctxt_switches: 1 nonvoluntary_ctxt_switches: 0 5640b9d4d000-5640b9d4e000 r--p 00000000 08:05 928442 /home/xinpengc/learn/cpp/cpp.out 5640b9d4e000-5640b9d4f000 r-xp 00001000 08:05 928442 /home/xinpengc/learn/cpp/cpp.out 5640b9d4f000-5640b9d50000 r--p 00002000 08:05 928442 /home/xinpengc/learn/cpp/cpp.out 5640b9d50000-5640b9d51000 r--p 00002000 08:05 928442 /home/xinpengc/learn/cpp/cpp.out 5640b9d51000-5640b9d52000 rw-p 00003000 08:05 928442 /home/xinpengc/learn/cpp/cpp.out 5640bb6df000-5640bb700000 rw-p 00000000 00:00 0 [heap] 7f8c07e56000-7f8c07e5a000 rw-p 00000000 00:00 0 7f8c07e5a000-7f8c07e5d000 r--p 00000000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7f8c07e5d000-7f8c07e6f000 r-xp 00003000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7f8c07e6f000-7f8c07e73000 r--p 00015000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7f8c07e73000-7f8c07e74000 r--p 00018000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7f8c07e74000-7f8c07e75000 rw-p 00019000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 7f8c07e75000-7f8c07e84000 r--p 00000000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 7f8c07e84000-7f8c07f2b000 r-xp 0000f000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 7f8c07f2b000-7f8c07fc2000 r--p 000b6000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 7f8c07fc2000-7f8c07fc3000 r--p 0014c000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 7f8c07fc3000-7f8c07fc4000 rw-p 0014d000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 7f8c07fc4000-7f8c07fe9000 r--p 00000000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7f8c07fe9000-7f8c08161000 r-xp 00025000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7f8c08161000-7f8c081ab000 r--p 0019d000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7f8c081ab000-7f8c081ac000 ---p 001e7000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7f8c081ac000-7f8c081af000 r--p 001e7000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7f8c081af000-7f8c081b2000 rw-p 001ea000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 7f8c081b2000-7f8c081b6000 rw-p 00000000 00:00 0 7f8c081b6000-7f8c0824c000 r--p 00000000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 7f8c0824c000-7f8c0833c000 r-xp 00096000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 7f8c0833c000-7f8c08385000 r--p 00186000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 7f8c08385000-7f8c08386000 ---p 001cf000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 7f8c08386000-7f8c08391000 r--p 001cf000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 7f8c08391000-7f8c08394000 rw-p 001da000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 7f8c08394000-7f8c08399000 rw-p 00000000 00:00 0 7f8c083ab000-7f8c083ac000 r--p 00000000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7f8c083ac000-7f8c083cf000 r-xp 00001000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7f8c083cf000-7f8c083d7000 r--p 00024000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7f8c083d8000-7f8c083d9000 r--p 0002c000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7f8c083d9000-7f8c083da000 rw-p 0002d000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 7f8c083da000-7f8c083db000 rw-p 00000000 00:00 0 7ffc9f0e5000-7ffc9f106000 rw-p 00000000 00:00 0 [stack] 7ffc9f16d000-7ffc9f170000 r--p 00000000 00:00 0 [vvar] 7ffc9f170000-7ffc9f171000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] xinpengc@xinpengc-VirtualBox:~/learn/cpp$
5,去掉pause之后的结果,和上面的结果差异不大:
1 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ gcc hello.c -o c.out 2 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ g++ hello.cpp -o cpp.out 3 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 4 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ stat c.out cpp.out 5 File: c.out 6 Size: 16688 Blocks: 40 IO Block: 4096 regular file 7 Device: 805h/2053d Inode: 928445 Links: 1 8 Access: (0775/-rwxrwxr-x) Uid: ( 1000/xinpengc) Gid: ( 1000/xinpengc) 9 Access: 2020-08-10 20:52:02.738419952 +0800 10 Modify: 2020-08-10 20:52:02.738419952 +0800 11 Change: 2020-08-10 20:52:02.738419952 +0800 12 Birth: - 13 File: cpp.out 14 Size: 17312 Blocks: 40 IO Block: 4096 regular file 15 Device: 805h/2053d Inode: 928442 Links: 1 16 Access: (0775/-rwxrwxr-x) Uid: ( 1000/xinpengc) Gid: ( 1000/xinpengc) 17 Access: 2020-08-10 20:52:12.123109624 +0800 18 Modify: 2020-08-10 20:52:12.123109624 +0800 19 Change: 2020-08-10 20:52:12.123109624 +0800 20 Birth: - 21 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ size c.out cpp.out 22 text data bss dec hex filename 23 1549 600 8 2157 86d c.out 24 2455 664 280 3399 d47 cpp.out 25 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 26 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ strip c.out cpp.out 27 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ stat c.out cpp.out 28 File: c.out 29 Size: 14464 Blocks: 32 IO Block: 4096 regular file 30 Device: 805h/2053d Inode: 928447 Links: 1 31 Access: (0775/-rwxrwxr-x) Uid: ( 1000/xinpengc) Gid: ( 1000/xinpengc) 32 Access: 2020-08-10 20:52:31.232658960 +0800 33 Modify: 2020-08-10 20:52:31.232658960 +0800 34 Change: 2020-08-10 20:52:31.232658960 +0800 35 Birth: - 36 File: cpp.out 37 Size: 14464 Blocks: 32 IO Block: 4096 regular file 38 Device: 805h/2053d Inode: 928445 Links: 1 39 Access: (0775/-rwxrwxr-x) Uid: ( 1000/xinpengc) Gid: ( 1000/xinpengc) 40 Access: 2020-08-10 20:52:31.244664959 +0800 41 Modify: 2020-08-10 20:52:31.244664959 +0800 42 Change: 2020-08-10 20:52:31.244664959 +0800 43 Birth: - 44 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ size c.out cpp.out 45 text data bss dec hex filename 46 1549 600 8 2157 86d c.out 47 2455 664 280 3399 d47 cpp.out 48 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 49 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 50 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 51 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ cat hello.c 52 #include <stdio.h> 53 #include <unistd.h> 54 55 int main(void) 56 { 57 printf("hello world\n"); 58 while (1) { 59 } 60 return 0x0; 61 } 62 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 63 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ cat hello.cpp 64 #include <iostream> 65 #include <cstdlib> 66 #include <unistd.h> 67 68 int main(void) 69 { 70 std::cout << "hello world" << std::endl; 71 while(1) { 72 } 73 return 0x0; 74 } 75 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 76 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ ./c.out & 77 [1] 2391 78 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ hello world 79 80 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ ./cpp.out & 81 [2] 2392 82 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ hello world 83 84 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ cat /proc/2391/status 85 Name: c.out 86 Umask: 0002 87 State: R (running) 88 Tgid: 2391 89 Ngid: 0 90 Pid: 2391 91 PPid: 2270 92 TracerPid: 0 93 Uid: 1000 1000 1000 1000 94 Gid: 1000 1000 1000 1000 95 FDSize: 256 96 Groups: 4 24 27 30 46 120 131 132 1000 97 NStgid: 2391 98 NSpid: 2391 99 NSpgid: 2391 100 NSsid: 2270 101 VmPeak: 2488 kB 102 VmSize: 2488 kB 103 VmLck: 0 kB 104 VmPin: 0 kB 105 VmHWM: 576 kB 106 VmRSS: 576 kB 107 RssAnon: 68 kB 108 RssFile: 508 kB 109 RssShmem: 0 kB 110 VmData: 180 kB 111 VmStk: 132 kB 112 VmExe: 8 kB 113 VmLib: 1644 kB 114 VmPTE: 48 kB 115 VmSwap: 0 kB 116 HugetlbPages: 0 kB 117 CoreDumping: 0 118 THP_enabled: 1 119 Threads: 1 120 SigQ: 0/7731 121 SigPnd: 0000000000000000 122 ShdPnd: 0000000000000000 123 SigBlk: 0000000000000000 124 SigIgn: 0000000000000000 125 SigCgt: 0000000000000000 126 CapInh: 0000000000000000 127 CapPrm: 0000000000000000 128 CapEff: 0000000000000000 129 CapBnd: 0000003fffffffff 130 CapAmb: 0000000000000000 131 NoNewPrivs: 0 132 Seccomp: 0 133 Speculation_Store_Bypass: vulnerable 134 Cpus_allowed: 1 135 Cpus_allowed_list: 0 136 Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001 137 Mems_allowed_list: 0 138 voluntary_ctxt_switches: 0 139 nonvoluntary_ctxt_switches: 991 140 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 141 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ cat /proc/2391/maps 142 55e8ec320000-55e8ec321000 r--p 00000000 08:05 928447 /home/xinpengc/learn/cpp/c.out 143 55e8ec321000-55e8ec322000 r-xp 00001000 08:05 928447 /home/xinpengc/learn/cpp/c.out 144 55e8ec322000-55e8ec323000 r--p 00002000 08:05 928447 /home/xinpengc/learn/cpp/c.out 145 55e8ec323000-55e8ec324000 r--p 00002000 08:05 928447 /home/xinpengc/learn/cpp/c.out 146 55e8ec324000-55e8ec325000 rw-p 00003000 08:05 928447 /home/xinpengc/learn/cpp/c.out 147 55e8ecae9000-55e8ecb0a000 rw-p 00000000 00:00 0 [heap] 148 7f7b12fd0000-7f7b12ff5000 r--p 00000000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 149 7f7b12ff5000-7f7b1316d000 r-xp 00025000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 150 7f7b1316d000-7f7b131b7000 r--p 0019d000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 151 7f7b131b7000-7f7b131b8000 ---p 001e7000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 152 7f7b131b8000-7f7b131bb000 r--p 001e7000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 153 7f7b131bb000-7f7b131be000 rw-p 001ea000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 154 7f7b131be000-7f7b131c4000 rw-p 00000000 00:00 0 155 7f7b131d6000-7f7b131d7000 r--p 00000000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 156 7f7b131d7000-7f7b131fa000 r-xp 00001000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 157 7f7b131fa000-7f7b13202000 r--p 00024000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 158 7f7b13203000-7f7b13204000 r--p 0002c000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 159 7f7b13204000-7f7b13205000 rw-p 0002d000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 160 7f7b13205000-7f7b13206000 rw-p 00000000 00:00 0 161 7ffcac716000-7ffcac737000 rw-p 00000000 00:00 0 [stack] 162 7ffcac781000-7ffcac784000 r--p 00000000 00:00 0 [vvar] 163 7ffcac784000-7ffcac785000 r-xp 00000000 00:00 0 [vdso] 164 ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] 165 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 166 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 167 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ cat /proc/2392/status 168 Name: cpp.out 169 Umask: 0002 170 State: R (running) 171 Tgid: 2392 172 Ngid: 0 173 Pid: 2392 174 PPid: 2270 175 TracerPid: 0 176 Uid: 1000 1000 1000 1000 177 Gid: 1000 1000 1000 1000 178 FDSize: 256 179 Groups: 4 24 27 30 46 120 131 132 1000 180 NStgid: 2392 181 NSpid: 2392 182 NSpgid: 2392 183 NSsid: 2270 184 VmPeak: 5876 kB 185 VmSize: 5876 kB 186 VmLck: 0 kB 187 VmPin: 0 kB 188 VmHWM: 1524 kB 189 VmRSS: 1524 kB 190 RssAnon: 152 kB 191 RssFile: 1372 kB 192 RssShmem: 0 kB 193 VmData: 228 kB 194 VmStk: 132 kB 195 VmExe: 8 kB 196 VmLib: 3344 kB 197 VmPTE: 44 kB 198 VmSwap: 0 kB 199 HugetlbPages: 0 kB 200 CoreDumping: 0 201 THP_enabled: 1 202 Threads: 1 203 SigQ: 0/7731 204 SigPnd: 0000000000000000 205 ShdPnd: 0000000000000000 206 SigBlk: 0000000000000000 207 SigIgn: 0000000000000000 208 SigCgt: 0000000000000000 209 CapInh: 0000000000000000 210 CapPrm: 0000000000000000 211 CapEff: 0000000000000000 212 CapBnd: 0000003fffffffff 213 CapAmb: 0000000000000000 214 NoNewPrivs: 0 215 Seccomp: 0 216 Speculation_Store_Bypass: vulnerable 217 Cpus_allowed: 1 218 Cpus_allowed_list: 0 219 Mems_allowed: 00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000001 220 Mems_allowed_list: 0 221 voluntary_ctxt_switches: 0 222 nonvoluntary_ctxt_switches: 2073 223 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 224 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ cat /proc/2392/maps 225 55f73d5c7000-55f73d5c8000 r--p 00000000 08:05 928445 /home/xinpengc/learn/cpp/cpp.out 226 55f73d5c8000-55f73d5c9000 r-xp 00001000 08:05 928445 /home/xinpengc/learn/cpp/cpp.out 227 55f73d5c9000-55f73d5ca000 r--p 00002000 08:05 928445 /home/xinpengc/learn/cpp/cpp.out 228 55f73d5ca000-55f73d5cb000 r--p 00002000 08:05 928445 /home/xinpengc/learn/cpp/cpp.out 229 55f73d5cb000-55f73d5cc000 rw-p 00003000 08:05 928445 /home/xinpengc/learn/cpp/cpp.out 230 55f73dfab000-55f73dfcc000 rw-p 00000000 00:00 0 [heap] 231 7fed2c836000-7fed2c83a000 rw-p 00000000 00:00 0 232 7fed2c83a000-7fed2c83d000 r--p 00000000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 233 7fed2c83d000-7fed2c84f000 r-xp 00003000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 234 7fed2c84f000-7fed2c853000 r--p 00015000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 235 7fed2c853000-7fed2c854000 r--p 00018000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 236 7fed2c854000-7fed2c855000 rw-p 00019000 08:05 1841148 /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 237 7fed2c855000-7fed2c864000 r--p 00000000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 238 7fed2c864000-7fed2c90b000 r-xp 0000f000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 239 7fed2c90b000-7fed2c9a2000 r--p 000b6000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 240 7fed2c9a2000-7fed2c9a3000 r--p 0014c000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 241 7fed2c9a3000-7fed2c9a4000 rw-p 0014d000 08:05 1841501 /usr/lib/x86_64-linux-gnu/libm-2.31.so 242 7fed2c9a4000-7fed2c9c9000 r--p 00000000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 243 7fed2c9c9000-7fed2cb41000 r-xp 00025000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 244 7fed2cb41000-7fed2cb8b000 r--p 0019d000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 245 7fed2cb8b000-7fed2cb8c000 ---p 001e7000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 246 7fed2cb8c000-7fed2cb8f000 r--p 001e7000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 247 7fed2cb8f000-7fed2cb92000 rw-p 001ea000 08:05 1840863 /usr/lib/x86_64-linux-gnu/libc-2.31.so 248 7fed2cb92000-7fed2cb96000 rw-p 00000000 00:00 0 249 7fed2cb96000-7fed2cc2c000 r--p 00000000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 250 7fed2cc2c000-7fed2cd1c000 r-xp 00096000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 251 7fed2cd1c000-7fed2cd65000 r--p 00186000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 252 7fed2cd65000-7fed2cd66000 ---p 001cf000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 253 7fed2cd66000-7fed2cd71000 r--p 001cf000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 254 7fed2cd71000-7fed2cd74000 rw-p 001da000 08:05 1841929 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 255 7fed2cd74000-7fed2cd79000 rw-p 00000000 00:00 0 256 7fed2cd8b000-7fed2cd8c000 r--p 00000000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 257 7fed2cd8c000-7fed2cdaf000 r-xp 00001000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 258 7fed2cdaf000-7fed2cdb7000 r--p 00024000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 259 7fed2cdb8000-7fed2cdb9000 r--p 0002c000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 260 7fed2cdb9000-7fed2cdba000 rw-p 0002d000 08:05 1840650 /usr/lib/x86_64-linux-gnu/ld-2.31.so 261 7fed2cdba000-7fed2cdbb000 rw-p 00000000 00:00 0 262 7ffcedcbf000-7ffcedce0000 rw-p 00000000 00:00 0 [stack] 263 7ffceddd5000-7ffceddd8000 r--p 00000000 00:00 0 [vvar] 264 7ffceddd8000-7ffceddd9000 r-xp 00000000 00:00 0 [vdso] 265 ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall] 266 xinpengc@xinpengc-VirtualBox:~/learn/cpp$ 267 xinpengc@xinpengc-VirtualBox:~/learn/cpp$