【问题标题】:status value in wait function and wexitstatus等待函数和 wexitstatus 中的状态值
【发布时间】:2014-08-23 22:39:16
【问题描述】:

我在一个unix系统函数的实现中读到了这个code(问题8.22):

        int status;
        if (wait(&status) > 0) {
             if (WIFEXITED(status)) {
                 return WEXITSTATUS(status);
             } else {
                 return status;
             }
        }

我不明白这里的 if 条件是什么:WEXITSTATUS 返回的状态与等待中的状态不一样吗?如果不是,那两者有什么区别?

【问题讨论】:

    标签: c process wait status wexitstatus


    【解决方案1】:

    status 值是一种复合值,包括进程“退出状态”和其他位。来自关于WEXITSTATUS的Linux手册页:

    如果 WIFEXITED(stat_val) 的值非零,则此宏计算 到子进程的状态参数的低 8 位 传递给 _exit() 或 exit(),或子进程返回的值 来自 main()。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多