【问题标题】:Interrupted system call for posix_memalignposix_memalign 系统调用中断
【发布时间】:2011-08-06 05:15:34
【问题描述】:

我在 posix_memalign 中遇到了这个异常。知道我们为什么会得到它吗?

提前致谢。

【问题讨论】:

  • 我正在将输出写入我的日志。
  • @Mat:我已经超载了 posix_memalign。那工作得很好。但是现在,我有一个标志。 if(flag){ return ob.registerPosix(memptr, alignment,size,LT_posix_memalign)} else return LT_POSIX_MEMALIGN(memptr, alignment, size) 整个代码都在 int posix_memalign( ) 函数内。
  • registerPosix - 只记录泄漏。因此,如果设置了标志,我们检查泄漏,否则不。

标签: c linux memory-management


【解决方案1】:

中断的系统调用通常是系统调用被中断的结果。换句话说,进程在调用执行时正在接收信号。

【讨论】:

    【解决方案2】:

    问题已解决:问题是对齐边界应该是 2 和 sizeof(void *) 的倍数。因此,如果海报大小为 4 字节,则第二个参数应为 4、8、16 等。我将其设置为仅 2 的倍数,因此它崩溃了。

    Wrong usage: crashes
    posix_memalign(&addr, 2, 8);
    
    Correct usage:
     posix_memalign(&addr, 4, 8); // Second argument multiple of void* and 2
    

    【讨论】:

    • 看起来你的错误是没有检查 posix_memalign 的返回值是否失败。
    • 是的,我没有检查 errno。我更关心泄漏:(
    • 检查errnoposix_memalign 不正确。错误号只是返回值。
    猜你喜欢
    • 2021-09-19
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 2015-07-14
    • 2016-02-01
    • 2016-01-30
    • 2014-10-07
    相关资源
    最近更新 更多