+ -
当前位置:首页 → 问答吧 → 请教高手一个问题 ptmalloc_lock_all陷入死循环

请教高手一个问题 ptmalloc_lock_all陷入死循环

时间:2010-07-09

来源:互联网

做嵌入式开发,里面使用了大量的system调用。经常出现CPU很高,达到90%多,后来通过GDB跟踪栈
发现调到ptmalloc_lock_all就一直出不来。根据网上查找的资料:
bash uses its own malloc implementation. Because of that, ptmalloc_init()
is never called in bash, and the malloc internal variables like main_arena
stay uninitialized. In particular, main_arena.next is a null pointer.

Now, bash calls fork(), which runs the fork prepare handlers in the Hurd,
among them ptmalloc_lock_all. The implementation of that crashes if
main_arena.next is a null pointer, because the for loop doesn't terminate

大致的意思是说一旦main_arena.next 是空指针,循环就永不停止,查看了glibc代码,有个for循环一直找地址,没找到就不退出。

我们这个工程很庞大,想不用system几乎不可能,有没有其他什么解决方法,谢谢大家!

作者: lishuxi2003   发布时间: 2010-07-09

本帖最后由 没本 于 2010-07-10 00:33 编辑

system发起者的内存脚印(footprint)太大,每次system会按footprint复制一份地址空间(fork的原理),哪怕你只是ls几个文件。因此要用system由一个很小的进程来发起,大进程想system时通过IPC机制通知那个小进程就发起system就行了。

作者: 没本   发布时间: 2010-07-09