在 Linux 服务器中,我运行一个程序并将其日志stdout
和stderr
输出记录到一个文件中:
myprogram.py > logfile 2>&1
stdout
所有到和 的输出stderr
都会被记录,除了以下一些错误不会出现在终端上。我想知道为什么不记录所有错误?
*** glibc detected *** xgboost: munmap_chunk(): invalid pointer: 0x0000000000bc0a10 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x75f4e)[0x7f089d19ef4e]
xxx/gcc/4.8.1/lib64/libgomp.so.1(+0x8d72)[0x7f089dc40d72]
xgboost[0x40b1de]
xgboost[0x41585d]
xgboost[0x403f81]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x7f089d147d5d]
xgboost[0x403fd9]
======= Memory map: ========
00400000-00437000 r-xp 00000000 00:13 2044979336 xxx/xgboost/v0.32/bin/xgboost
00437000-00439000 rw-p 00037000 00:13 2044979336 xxx/xgboost/v0.32/bin/xgboost
00bae000-00d3c000 rw-p 00000000 00:00 0 [heap]
7f0897791000-7f0897792000 ---p 00000000 00:00 0
7f0897792000-7f0898192000 rw-p 00000000 00:00 0
7f0898192000-7f0898193000 ---p 00000000 00:00 0
7f0898193000-7f0898b93000 rw-p 00000000 00:00 0
7f0898b93000-7f0898b94000 ---p 00000000 00:00 0
7f0898b94000-7f0899594000 rw-p 00000000 00:00 0
7f0899594000-7f0899595000 ---p 00000000 00:00 0
7f0899595000-7f0899f95000 rw-p 00000000 00:00 0
7f0899f95000-7f0899f96000 ---p 00000000 00:00 0
7f0899f96000-7f089a996000 rw-p 00000000 00:00 0
7f089a996000-7f089a997000 ---p 00000000 00:00 0
7f089a997000-7f089b397000 rw-p 00000000 00:00 0
7f089b397000-7f089b398000 ---p 00000000 00:00 0
7f089b398000-7f089c599000 rw-p 00000000 00:00 0
7f089cd1d000-7f089cd24000 r-xp 00000000 fc:01 414519 /lib64/librt-2.12.so
7f089cd24000-7f089cf23000 ---p 00007000 fc:01 414519 /lib64/librt-2.12.so
7f089cf23000-7f089cf24000 r--p 00006000 fc:01 414519 /lib64/librt-2.12.so
7f089cf24000-7f089cf25000 rw-p 00007000 fc:01 414519 /lib64/librt-2.12.so
7f089cf25000-7f089cf27000 r-xp 00000000 fc:01 414530 /lib64/libdl-2.12.so
7f089cf27000-7f089d127000 ---p 00002000 fc:01 414530 /lib64/libdl-2.12.so
7f089d127000-7f089d128000 r--p 00002000 fc:01 414530 /lib64/libdl-2.12.so
7f089d128000-7f089d129000 rw-p 00003000 fc:01 414530 /lib64/libdl-2.12.so
7f089d129000-7f089d2b3000 r-xp 00000000 fc:01 414538 /lib64/libc-2.12.so
7f089d2b3000-7f089d4b3000 ---p 0018a000 fc:01 414538 /lib64/libc-2.12.so
7f089d4b3000-7f089d4b7000 r--p 0018a000 fc:01 414538 /lib64/libc-2.12.so
7f089d4b7000-7f089d4b8000 rw-p 0018e000 fc:01 414538 /lib64/libc-2.12.so
7f089d4b8000-7f089d4bd000 rw-p 00000000 00:00 0
7f089d4bd000-7f089d4d4000 r-xp 00000000 fc:01 393354 /lib64/libpthread-2.12.so
7f089d4d4000-7f089d6d4000 ---p 00017000 fc:01 393354 /lib64/libpthread-2.12.so
7f089d6d4000-7f089d6d5000 r--p 00017000 fc:01 393354 /lib64/libpthread-2.12.so
7f089d6d5000-7f089d6d6000 rw-p 00018000 fc:01 393354 /lib64/libpthread-2.12.so
7f089d6d6000-7f089d6da000 rw-p 00000000 00:00 0
7f089d6da000-7f089d75d000 r-xp 00000000 fc:01 414534 /lib64/libm-2.12.so
7f089d75d000-7f089d95c000 ---p 00083000 fc:01 414534 /lib64/libm-2.12.so
7f089d95c000-7f089d95d000 r--p 00082000 fc:01 414534 /lib64/libm-2.12.so
7f089d95d000-7f089d95e000 rw-p 00083000 fc:01 414534 /lib64/libm-2.12.so
7f089d95e000-7f089d95f000 r-xp 00000000 fc:01 393364 /lib64/snoopy.so
7f089d95f000-7f089db5e000 ---p 00001000 fc:01 393364 /lib64/snoopy.so
7f089db5e000-7f089db5f000 rw-p 00000000 fc:01 393364 /lib64/snoopy.so
7f089db5f000-7f089db7f000 r-xp 00000000 fc:01 414524 /lib64/ld-2.12.so
7f089dc1c000-7f089dc22000 rw-p 00000000 00:00 0
7f089dc22000-7f089dc37000 r-xp 00000000 00:13 2044935698 xxx/gcc/4.8.1/lib64/libgcc_s.so.1
7f089dc37000-7f089dc38000 rw-p 00015000 00:13 2044935698 xxx/gcc/4.8.1/lib64/libgcc_s.so.1
7f089dc38000-7f089dc45000 r-xp 00000000 00:13 2044935716 xxx/gcc/4.8.1/lib64/libgomp.so.1.0.0
7f089dc45000-7f089dc46000 rw-p 0000d000 00:13 2044935716 xxx/gcc/4.8.1/lib64/libgomp.so.1.0.0
7f089dc74000-7f089dc76000 rw-p 00000000 00:00 0
7f089dc76000-7f089dd5a000 r-xp 00000000 00:13 2044935770 xxx/gcc/4.8.1/lib64/libstdc++.so.6.0.18
7f089dd5a000-7f089dd5b000 ---p 000e4000 00:13 2044935770 xxx/gcc/4.8.1/lib64/libstdc++.so.6.0.18
7f089dd5b000-7f089dd63000 r--p 000e4000 00:13 2044935770 xxx/gcc/4.8.1/lib64/libstdc++.so.6.0.18
7f089dd63000-7f089dd65000 rw-p 000ec000 00:13 2044935770 xxx/gcc/4.8.1/lib64/libstdc++.so.6.0.18
7f089dd65000-7f089dd7c000 rw-p 00000000 00:00 0
7f089dd7c000-7f089dd7e000 rw-p 00000000 00:00 0
7f089dd7e000-7f089dd7f000 r--p 0001f000 fc:01 414524 /lib64/ld-2.12.so
7f089dd7f000-7f089dd80000 rw-p 00020000 fc:01 414524 /lib64/ld-2.12.so
7f089dd80000-7f089dd81000 rw-p 00000000 00:00 0
7ffcf1520000-7ffcf156f000 rw-p 00000000 00:00 0 [stack]
7ffcf15ec000-7ffcf15ed000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
答案1
你的程序只是写入除 1 或 2 之外的描述符。
考虑以下脚本:
#!/bin/bash
echo test >$(tty)
现在让我们运行它,将 stdin 和 stderr 重定向到 /dev/null:
$ ./script >/dev/null 2>&1
test
正如您所看到的,我们在内部将输出重定向到终端,因此外部重定向到 /dev/null 没有任何作用。在你的情况下,似乎某些调试模块正在做类似的事情。