吾用ping测试,结果崩溃了,而且莫名其妙的.难道是晚上跑,内存用光了?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./gh_manager thread false 1'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 malloc_consolidate (av=av@entry=0x7f8af8000020) at malloc.c:4167
4167 malloc.c: 没有那个文件或目录.
[Current thread is 1 (Thread 0x7f8ba1fff700 (LWP 25566))]
(gdb) backtrace
#0 malloc_consolidate (av=av@entry=0x7f8af8000020) at malloc.c:4167
#1 0x00007f8c5ec95cde in _int_malloc (av=av@entry=0x7f8af8000020,
bytes=bytes@entry=4096) at malloc.c:3450
#2 0x00007f8c5ec98184 in __GI___libc_malloc (bytes=bytes@entry=4096)
at malloc.c:2913
#3 0x00007f8c5ec811d5 in __GI__IO_file_doallocate (fp=0x7f8af8000a00)
at filedoalloc.c:127
#4 0x00007f8c5ec8f594 in __GI__IO_doallocbuf (fp=fp@entry=0x7f8af8000a00)
at genops.c:398
#5 0x00007f8c5ec8e69c in _IO_new_file_underflow (fp=0x7f8af8000a00)
at fileops.c:556
#6 0x00007f8c5ec8f60e in __GI__IO_default_uflow (fp=0x7f8af8000a00)
at genops.c:413
#7 0x00007f8c5ec82c6a in __GI__IO_getline_info (fp=fp@entry=0x7f8af8000a00,
buf=buf@entry=0x7f8ba1ffd080 "ping -c 1 192.168.1.104", n=1023,
delim=delim@entry=10, extract_delim=extract_delim@entry=1,
eof=eof@entry=0x0) at iogetline.c:60
#8 0x00007f8c5ec82d78 in __GI__IO_getline (fp=fp@entry=0x7f8af8000a00,
buf=buf@entry=0x7f8ba1ffd080 "ping -c 1 192.168.1.104",
n=, delim=delim@entry=10,
extract_delim=extract_delim@entry=1) at iogetline.c:34
#9 0x00007f8c5ec81b7d in _IO_fgets (
buf=0x7f8ba1ffd080 "ping -c 1 192.168.1.104", n=,
---Type to continue, or q to quit---
fp=0x7f8af8000a00) at iofgets.c:53
#10 0x00007f8c5ea10431 in ping_ip (ip=0x7f8ba1ffd530 "192.168.1.104")
at gh_kit.cpp:88
解决办法:
读取ping的结果时,不要用gets(),而是通过>输出到文件,然后读取这个文件。