【问题标题】:how do I fix core dump?如何修复核心转储?
【发布时间】:2020-04-30 07:11:13
【问题描述】:

我正在通过这个小程序获取核心转储。

#include <dirent.h>
int main(void) {

        printf("process n%s",(long)getpid());
        exit(0);
}

你能解释一下为什么吗?

【问题讨论】:

  • 请查看getpid 手册页,尤其是它的返回值。
  • 您正在尝试使用用于打印字符串的%s 格式说明符打印long。这不会有好的结局。
  • getpid()的返回值使用的数据类型是pid_t,它是一个整数类型

标签: c coredump


【解决方案1】:

您需要知道您的函数来自哪里、它们返回什么以及如何打印返回值。

#include <unistd.h>
#include <stdio.h>

int main(void) {
    printf("process n%ld", (long)getpid());
}

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    • 2019-09-03
    • 1970-01-01
    • 2017-07-24
    • 2020-02-04
    相关资源
    最近更新 更多