- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
运行以下代码的进程因段错误而崩溃:
#include <stdlib.h>
#include <iostream>
#include <pthread.h>
void* f( void* )
{
while( true )
{
// It crashes inside this call (with cerr, too).
std::cout << 0;
}
return NULL;
}
int main()
{
pthread_t t;
pthread_create( &t, NULL, &f, NULL );
while( true )
{
// It crashes with any script/app; true is just simple.
system( "true" );
}
return 0;
}
它会在几秒钟内崩溃(输出有数千到数百万个“0”)。它使 cout << 0
中的一些函数崩溃。用上面的代码调用。取决于在 f()
中调用的额外函数或放入堆栈的数据,它在不同的地方崩溃。在 gdb 中,有时堆栈对于函数调用的顺序没有意义。据此我推断堆栈已损坏。
我发现有一些 problems with multi-threaded applications calling fork() (另请参阅其中两条提到堆栈损坏的评论)。如果未将文件描述符设置为 FD_CLOEXEC
,则 fork /克隆进程会复制文件描述符。 .但是,没有明确创建的文件描述符。 (我尝试在 FD_CLOEXEC
和 fileno( stdout )
上设置 fileno( stderr )
,但没有任何积极的变化。)
即使没有明确的文件描述符,我也不能混合使用线程和 fork()
?我是否只需要更换 system()
调用具有同等功能?还是内核中存在导致此崩溃的错误并已在 2.6.30 之后修复?
我在 ARM AT91 处理器 (armv5tejl) 上运行它,Linux 2.6.30(针对我的特定外围设备集有一些覆盖和补丁)用 GCC 4.3.2 编译。
Linux 2.6.30 #1 Thu May 29 15:43:04 CDT 2014 armv5tejl GNU/Linux
我一直在用 -g
[交叉] 编译它和 -O0
,但没有这些它仍然会崩溃:
arm-atmel-linux-gnueabi-g++ -o system_thread system_thread.cpp -lpthread
我也试过 -fstack-protector-all
标志:有时它会在 __stack_chk_fail()
中崩溃,但有时其他函数指针或数据会损坏,并且会更早崩溃。
它加载的库(来自 strace):
libpthread.so.0
libstdc++.so.6
libm.so.6
libgcc_s.so.1
libc.so.6
注意:因为它有时不会崩溃并且不会真正响应 ^C
,我通常在后台运行它:
$ killall -9 system_thread; rm -f log; system_thread >log &
我已经为几个不同的体系结构和 Linux 内核版本编译了这个程序,但我没有看到它在其他任何地方崩溃:
Linux 3.10.29 #1 Wed Feb 12 17:12:39 CST 2014 armv5tejl GNU/Linux
Linux 3.6.0-dirty #3 Wed May 28 13:53:56 CDT 2014 microblaze GNU/Linux
Linux 3.13.0-27-generic #50-Ubuntu SMP Thu May 15 18:06:16 UTC 2014 x86_64 x86_64 GNU/Linux
Linux 3.8.0-35-generic #50~precise1-Ubuntu SMP Wed Dec 4 17:25:51 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
编辑:请注意,在相同的体系结构 (armv5tejl) 上,它不会与 Linux 3.10.29 一起崩溃。此外,在我的“设备”(较旧的服务器和客户端应用程序)的早期版本上运行时,它不会崩溃,具有相同版本的 Linux - 2.6.30。所以操作系统的环境有一定的影响。
BusyBox v1.20.1 提供sh
那system()
电话。
最佳答案
这可以在使用您提到的 2.6.30 内核的 ARM 处理器上重现,但不能在 master 中重现。我们可以使用 git bisect
找到修复此错误的位置(大约需要 16 次迭代)。请注意,由于 git bisect
旨在寻找回归,但在这种情况下 master 是“好”的,而过去的版本是“坏的”,我们需要 reverse the meanings of "good" and "bad" .
二分法发现的罪魁祸首是this commit , 以修复涉及 fork() 的“用户空间数据损坏实例”。此症状与您描述的症状非常相似,也可能损坏堆栈外的内存。在向后移植此提交和 the required parent 之后到 2.6.30 内核,您发布的代码不再崩溃。
关于c++ - 线程循环 system() 和 cout 破坏堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23966310/
我正在尝试完成撤消/重做。我正在使用loadFromJSON(...)从我存储在数组中的 Canvas 状态重新构建 Canvas 。基本上,我的想法是破坏现有的 Canvas 并重新构建 Canva
在某些情况下,我有一个在 iframe 中打开的网页。当它被加载到那个 iframe 中时,我需要它将窗口位置设置为资源以下载文件(所有这些都是为了更新 GreaseMonkey 脚本......所有
当我创建 Intent 时: Intent in = new Intent(this, myclass.class); this.startActivity(in); 我创建了一个新的 Intent
我正在我本地版本的 Wordpress 网站上为 Wordpress 创建新的短代码。 在 functions.php 中,我添加了例如: function shortTest() { re
我正在为机械网站制作 JavaScript 闪卡游戏。因为我想将方程写在卡片上,所以我需要使用 delta(Δ) 符号。 一张卡片可能有:一侧是“功率方程”,另一侧是“P=W/Δt”。如果卡片从第一面
我编写了以下代码: document.addEventListener("DOMContentLoaded", ()=>{ let menu = document.querySelector(
我的浏览器同步工作正常,但我仍然很难处理之前的 html 的缓存。即使选中了 Chrome 的“禁用缓存”,甚至在隐身模式下也是如此! 要加载页面更改,我总是必须“清除缓存并硬重新加载”。 我想知道,
我注意到每次打开和关闭(通过单击菜单项或单击菜单外的某个区域)时,上下文菜单 ( Ext.menu.Menu ) s 不会从 DOM 中删除,它们只是以某种方式变得不可见。 如何改变这个? 最佳答案
给定依赖记录类型: Record FinPath : Type := mkPath { fp_head : S i; fp_tail
在 Husdon/Jenkins 中,我可以在构建被破坏时设置通知,以向进行破坏构建的 checkin 的用户发送电子邮件。如何在 Teamcity 中执行此操作? 我知道个人用户可以通过 Teamc
我注意到每次打开和关闭(通过单击菜单项或单击菜单外的某个区域)时,上下文菜单 ( Ext.menu.Menu ) s 不会从 DOM 中删除,它们只是以某种方式变得不可见。 如何改变这个? 最佳答案
使用 MIMEMultipart('alternative') 发送 html 和 pain-text 时 将 html 转换为文本时,html 的 anchor 换行 http://127.0.0.
每当我的应用程序最小化时,我都会启动一个服务,该服务向我的 HTTP 服务器发送拉取请求以检查通知,当应用程序恢复时,服务将被终止(以及计划的可运行项)。一切正常,直到我决定终止该应用程序(将其从正在
我意识到该框架处于 alpha 阶段,但正在实现 jQuery Mobile破坏了我的omniauth 身份验证。当我尝试登录时,一旦我尝试点击/auth/twitter Controller ,jQ
我对 Angular 比较陌生,经过几个小时的调试,我发现添加 jquery 时存在一些不兼容性。该指令在没有 jquery 的情况下工作正常,但在使用 jquery 时会中断:/ 这是一个 plnk
我发现,因为我正在处理的所有表单都有一个包含“name =“submit””属性的提交按钮,所以当我单击应该触发表单提交的链接时,触发器提交会中断. 有谁知道我该如何解决这个问题。 下面的 JQuer
我遇到了一个问题:/我得到了一个 CSS 东西,它使悬停时背景位置发生变化。但是当我在 javascript 中运行一个改变悬停的函数后,CSS 停止工作。 这是函数: function tree()
谁能给出一个完整的例子来说明 qooxdoo 1.6 中的 dispose 和 destruct 是如何工作的? ,我在 qooxdoo 演示或文档中找不到任何好的示例。 谢谢你的建议。 最佳答案 处
我对 JFormattedTextField 有疑问(我将它用作我们所有文本字段的基类)。 今天我尝试向该字段的文档添加一个文档过滤器,它工作得很好,但前提是它没有设置格式化程序工厂。 问题是,当设置
我有一个点击事件 $('#ship_Move').click(function (event) { event.stopPropagation();
我是一名优秀的程序员,十分优秀!