电脑能玩网游微信能上qq微信但是上不了百度或者淘宝等 但有些网页能打开 手机连上wifi也打不开百度

博客访问: 574412
博文数量: 166
博客积分: 4004
博客等级: 中校
技术积分: 2078
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: LINUX
在程序不寻常退出时,内核会在当前工作目录下生成一个core文件(是一个内存映像,同时加上调试信息)。使用gdb来查看core文件,可以指示出导致程序出错的代码所在文件和行数。1.core文件的生成开关和大小限制&&1)使用ulimit -c命令可查看core文件的生成开关。若结果为0,则表示关闭了此功能,不会生成core文件。&2) 使用ulimit -c filesize命令,可以限制core文件的大小(filesize的单位为kbyte)。若ulimit -c unlimited,则表示core文件的大小不受限制。如果生成的信息超过此大小,将会被裁剪,最终生成一个不完整的core文件。在调试此core文 件的时候,gdb会提示错误。2.core文件的名称和生成路径&core文件生成路径:输入可执行文件运行命令的同一路径下。若系统生成的core文件不带其它任何扩展名称,则全部命名为core。新的core文件生成将覆盖原来的core文件。1)/proc/sys/kernel/core_uses_pid可以控制core文件的文件名中是否添加pid作为扩展。文件内容为1,表示添加pid作为扩展名,生成的core文件格式为core.xxxx;为0则表示生成的core文件同一命名为core。可通过以下命令修改此文件:echo "1" & /proc/sys/kernel/core_uses_pid2)proc/sys/kernel/core_pattern可以控制core文件保存位置和文件名格式。可通过以下命令修改此文件:echo "/corefile/core-%e-%p-%t" & core_pattern,可以将core文件统一生成到/corefile目录下,产生的文件名为core-命令名-pid-时间戳以下是参数列表:&&& %p - insert pid into filename 添加pid&&& %u - insert current uid into filename 添加当前uid&&& %g - insert current gid into filename 添加当前gid&&& %s - insert signal that caused the coredump into the filename 添加导致产生core的信号&&& %t - insert UNIX time that the coredump occurred into filename 添加core文件生成时的unix时间&&& %h - insert hostname where the coredump happened into filename 添加主机名&&& %e - insert coredumping executable name into filename 添加命令名3.core文件的查看&&core文件需要使用gdb来查看。&gdb ./a.out&core-file core.xxxx&使用bt命令即可看到程序出错的地方。&以下两种命令方式具有相同的效果,但是在有些环境下不生效,所以推荐使用上面的命令。&1)gdb -core=core.xxxxfile ./a.outbt&2)gdb -c core.xxxxfile ./a.outbt4.开发板上使用core文件调试&如果开发板的操作系统也是linux,core调试方法依然适用。如果开发板上不支持gdb,可将开发板的环境(依赖库)、可执行文件和core文件拷贝到PC的linux下。在 PC上调试开发板上产生的core文件,需要使用交叉编译器自带的gdb,并且需要在gdb中指定solib-absolute-prefix和 solib-search-path两个变量以保证gdb能够找到可执行程序的依赖库路径。有一种建立配置文件的方法,不需要每次启动gdb都配置以上变 量,即:在待运行gdb的路径下建立.gdbinit。配置文件内容:set solib-absolute-prefix YOUR_CROSS_COMPILE_PATHset solib-search-path YOUR_CROSS_COMPILE_PATHset solib-search-path YOUR_DEVELOPER_TOOLS_LIB_PATHhandle SIG32 nostop noprint pass注意:待调试的可执行文件,在编译的时候需要加-g,core文件才能正常显示出错信息!有时候core信息很大,超出了开发板的空间限制,生成的core信息会残缺不全而无法使用,可以通过挂载到PC的方式来规避这一点。&&&5. core 文件&&& * 开启或关闭core文件的生成ulimit -c 可以查看是否打开此选项,若为0则为关闭;ulimit -c 0可手动关闭ulimit -c 1000 为设置core文件大小最大为1000kulimit -c unlimited 设置core文件大小为不限制大小&很多系统在默认的情况下是关闭生成core文件的,这个命令可以加到你的profile中去6.设置Core Dump的核心转储文件目录和命名规则&在默认的情况下,很多系统的core文件是生成在你运行程序的目录下,或者你在程序中chdir后的那个目录,然后在core文件的后面加了一个 pid。在实际工作中,这样可能会造成很多目录下产生core文件,不便于管理,实际上,在2.6下,core文件的生成位置和文件名的命名都是可以配置 的。&/proc/sys/kernel/core_uses_pid可以控制产生的core文件的文件名中是否添加pid作为扩展,如果添加则文件内容为1,否则为0proc/sys/kernel/core_pattern可以设置格式化的core文件保存位置或文件名,比如原来文件内容是core-%e可以这样修改:echo "/tmp/core-%e-%p" & core_pattern将会控制所产生的core文件会存放到/corefile目录下,产生的文件名为core-命令名-pid-时间戳以下是参数列表:&&& %p - insert pid into filename 添加pid&&& %u - insert current uid into filename 添加当前uid&&& %g - insert current gid into filename 添加当前gid&&& %s - insert signal that caused the coredump into the filename 添加导致产生core的信号&&& %t - insert UNIX time that the coredump occurred into filename 添加core文件生成时的unix时间&&& %h - insert hostname where the coredump happened into filename 添加主机名&&& %e - insert coredumping executable name into filename 添加命令名当然,你可以用下列方式来完成sysctl -w kernel.core_pattern=/tmp/core-%e-%p&这些操作一旦计算机重启,则会丢失,如果你想持久化这些操作,可以在 /etc/sysctl.conf文件中增加:kernel.core_pattern=/tmp/core%p&加好后,如果你想不重启看看效果的话,则用下面的命令:sysctl -p /etc/sysctl.conf一个例子Linux下的C程序常常会因为内存访问错误等原因造成segment fault(段错误),此时如果系统core dump功能是打开的,那么将会有内存映像转储到硬盘上来,之后可以用gdb对core文件进行分析,还原系统发生段错误时刻的堆栈情况。这对于我们发现 程序bug很有帮助。使用ulimit -a可以查看系统core文件的大小限制;使用ulimit -c [kbytes]可以设置系统允许生成的core文件大小,例如ulimit -c 0 不产生core文件ulimit -c 100 设置core文件最大为100kulimit -c unlimited 不限制core文件大小先看一段会造成段错误的程序:[c]&&&编译运行后结果如下:[&leconte@&localhost&test&]&$&gcc&-g&-o&test&a.c[&leconte@&localhost&test&]&$ ./&test&段错误此时并没有产生core文件,接下来使用ulimit -c设置core文件大小为无限制,再执行./test程序,结果如下:[&leconte@&localhost ~]&$&ulimit&-a&core&file&size&(&blocks, -c)&0&.........[&leconte@&localhost&test&]&$&ulimit&-c&unlimited[&leconte@&localhost&test&]&$&ulimit&-a&core&file&size&(&blocks, -c)&unlimited..............[&leconte@&localhost&test&]&$ ./&test&段错误&(&core dumped)&[&leconte@&localhost&test&]&$&ls&-al&core.*&-rw-------&1&leconte leconte&139264&01-06&22&:31&core.2065可见core文件已经生成,接下来可以用gdb分析,查看堆栈情况:[&leconte@&localhost&test&]&$&gdb&./&test&core.2065GNU&gdb&Fedora&(&6.8&-27.el5)&Copyright&(&C)&2008&Free Software Foundation, Inc.License GPLv3+: GNU GPL version&3&or later&&&http://&gnu.org/&licenses/&gpl.html&&This is&free&software: you are&free&to change and redistribute it.There is NO WARRANTY, to the extent permitted by law. Type&"show copying"&and&"show warranty"&for&details.This GDB was configured&as&"i386-redhat-linux-gnu"&...&warning:&exec&file&is newer than core file.&warning: Can't read pathname for load map: Input/output error.Reading symbols from /lib/libc.so.6...done.Loaded symbols for /lib/libc.so.6Reading symbols from /lib/ld-linux.so.2...done.Loaded symbols for /lib/ld-linux.so.2Core was generated by `./test'&.Program terminated with signal&11&, Segmentation fault.[&New process&2065&]&#0 0x0804836f in main () at a.c:6&6&*&ptr&=0&;从上述输出可以清楚的看到,段错误出现在a.c的第6行,问题已经清晰地定位到了。很多系统默认的core文件大小都是0,我们可以通过在shell的启动脚本/etc/bashrc或者~/.bashrc等地方来加入 ulimit -c 命令来指定core文件大小,从而确保core文件能够生成。除此之外,还可以在/proc/sys/kernel/core_pattern里设置core文件的文件名模板,详情请看core的官方man
阅读(2237) | 评论(2) | 转发(3) |
相关热门文章
给主人留下些什么吧!~~
使用ulimit -c命令可查看core文件的生成开关
写的不错,学习一下
请登录后评论。7941人阅读
1.core文件的生成开关和大小限制
---------------------------------
1)使用ulimit
-c命令可查看core文件的生成开关。若结果为0,则表示关闭了此功能,不会生成core文件。
使用ulimit
-cfilesize命令,可以限制core文件的大小(filesize的单位为kbyte)。若ulimit
-cunlimited,则表示core文件的大小不受限制。如果生成的信息超过此大小,将会被裁剪,最终生成一个不完整的core文件。在调试此
core文件的时候,gdb会提示错误。
2.core文件的名称和生成路径
----------------------------
一、设置core文件相关参数
若系统生成的core文件不带其它任何扩展名称,则全部命名为core。新的core文件生成将覆盖原来的core文件。
1)/proc/sys/kernel/core_uses_pid可以控制core文件的文件名中是否添加pid作为扩展。文件内容为1,表示添加pid作为扩展名,生成的core文件格式为core.xxxx;为0则表示生成的core文件同一命名为core。
可通过以下命令修改此文件:
/proc/sys/kernel/core_uses_pid
2)proc/sys/kernel/core_pattern可以控制core文件保存位置和文件名格式。
可通过以下命令修改此文件:
&/corefile/core-%e-%p-%t& &
core_pattern,可以将core文件统一生成到/corefile目录下,产生的文件名为core-命令名-pid-时间戳
以下是参数列表:
%p - insert pid into filename 添加pid
%u - insert current uid into filename 添加当前uid
%g - insert current gid into filename 添加当前gid
%s - insert signal that caused the coredump into the filename
添加导致产生core的信号
%t - insert UNIX time that the coredump occurred into filename
添加core文件生成时的unix时间
%h - insert hostname where the coredump happened into filename
添加主机名
%e - insert coredumping executable name into filename
添加命令名
二、.用gdb查看core文件:
发生coredump之后,用gdb进行查看core文件的内容,以定位文件中引发coredump的行.
gdb [execfile] [core file]
gdb ./test core.22773
gdb core_dump_test core.22773
在进入gdb后,
用bt命令查看backtrace以检查发生程序运行到哪里,
来定位core dump的文件-&行.
三、调试core文件
Unix系统下,应用程序崩溃,一般会产生core文件,如何根据core文件查找问题的所在,并做相应的分析和调试,是非常重要的,本文对此做简单介绍。
例如,一个程序cmm_test_tool在运行的时候发生了错误,并生成了一个core文件,如下:
-rw-r–r– 1 root cmm_test_tool.c
-rw-r–r– 1 root cmm_test_tool.o
-rwxr-xr-x 1 root cmm_test_tool
-rw——- 1 root core.19344
-rw——- 1 root core.19351
-rw-r–r– 1 root cmm_test_tool.cfg
-rw-r–r– 1 root cmm_test_tool.res
-rw-r–r– 1 root cmm_test_tool.log
[root@AUTOTEST_SIM2 mam2cm]#
就可以利用命令gdb进行查找,参数一是应用程序的名称,参数二是core文件,运行
gdb cmm_test_tool core.19344结果如下:
[root@AUTOTEST_SIM2 mam2cm]# gdb cmm_test_tool core.19344
GNU gdb Red Hat Linux (5.2.1-4)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type “show copying” to see the conditions.
There is absolutely no warranty for GDB. Type “show warranty” for details.
This GDB was configured as “i386-redhat-linux”…
Core was generated by `./cmm_test_tool’.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/i686/libpthread.so.0…done.
Loaded symbols for /lib/i686/libpthread.so.0
Reading symbols from /lib/i686/libm.so.6…done.
Loaded symbols for /lib/i686/libm.so.6
Reading symbols from /usr/lib/libz.so.1…done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /usr/lib/libstdc++.so.5…done.
Loaded symbols for /usr/lib/libstdc++.so.5
Reading symbols from /lib/i686/libc.so.6…done.
Loaded symbols for /lib/i686/libc.so.6
Reading symbols from /lib/libgcc_s.so.1…done.
Loaded symbols for /lib/libgcc_s.so.1
Reading symbols from /lib/ld-linux.so.2…done.
Loaded symbols for /lib/ld-linux.so.2
Reading symbols from /lib/libnss_files.so.2…done.
Loaded symbols for /lib/libnss_files.so.2
#0 0x4202cec1 in __strtoul_internal () from /lib/i686/libc.so.6
进入gdb提示符,输入where,找到错误发生的位置和堆栈,如下:
(gdb) where
#0 0x4202cec1 in __strtoul_internal () from /lib/i686/libc.so.6
#1 0x in strtoul () from /lib/i686/libc.so.6
#2 0x0804b4da in GetMaxIDFromDB (get_type=2, max_id=0x806fd20) at cmm_test_tool.c:788
#3 0x in ConstrctVODProgram (vod_program=0x40345bdc) at cmm_test_tool.c:946
#4 0x in TVRequestThread (arg=0×0) at cmm_test_tool.c:372
#5 0× in pthread_start_thread () from /lib/i686/libpthread.so.0
至此,可以看出文件出错的位置是函数 GetMaxIDFromDB ,两个参数分别是2和0x806fd20,这个函数位于源代码的788行,基于此,我们就可以有针对性的找到问题的根源,并加以解决。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:298333次
积分:3156
积分:3156
排名:第10365名
原创:53篇
转载:66篇
评论:33条
(1)(1)(2)(1)(1)(9)(13)(9)(1)(27)(10)(23)(1)(3)(17)Linux coredump 的打开和关闭
Linux coredump 的打开和关闭
编辑:www.fx114.net
本篇文章主要介绍了"Linux coredump 的打开和关闭",主要涉及到Linux coredump 的打开和关闭方面的内容,对于Linux coredump 的打开和关闭感兴趣的同学可以参考一下。
(转载自 .cn/s/blog_6blazj.html)
ulimit -c 输出如果为0,则说明coredump没有打开
ulimit -c 输出如果为unlimited,则说明coredump已打开
通过 ulimit -c unlimited 就可以打开它,
通过 ulimit -c 0 就可以关闭它
通过上面的命令修改后,一般都只是对当前会话起作用,当你下次重新登录后,还是要重新输入上面的命令,所以很麻烦。我们可以把通过修改/etc/profile文件 来使系统每次自动打开。
步骤如下:
1.首先打开/etc/profile文件
一般都可以在文件中找到 这句语句:ulimit -S -c 0 & /dev/null2&&1.ok,根据上面的例子,我们只要把那个0 改为unlimited 就ok了。然后保存退出。
2.通过source /etc/profile 使当期设置生效。
3.通过ulimit -c 查看下是否已经打开。
本站评论功能暂时取消,后续此功能例行通知。
本文标题:
本页链接:

我要回帖

更多关于 qq号微信注册 的文章

 

随机推荐