gpt4 book ai didi

c++ - 应用程序的返回码是一个 int16_t?

转载 作者:行者123 更新时间:2023-12-03 09:38:09 25 4
gpt4 key购买 nike

在谈论启动新进程时,您可以使用 int system(char* command) 来实现。 .如果您通过 非空 参数,你可以得到:

  • -1如果子进程无法启动;
  • 否则子进程的返回码;

  • note: in Unix/Linux the return code is located on the higher eight bits of the result, while the lower eight bits contain the termination reason code>{1}<, so a retcode equal to 1 will be returned as 256; you can get the actual return code by shifting the value eight bits to the right; there is also a macro named WEXITSTATUS() that does it for you.


    搜索 the implementationWEXITSTATUS()它是右移 8 位。 #define WEXITSTATUS(x) (_W_INT(x) >> 8)这就是为什么我倾向于认为返回码是 2 个字节的原因(也来自 >{1}<)。引用来自在线找到的 C 类(class)。
    P.s 我想知道返回码和终止原因码之间的区别,它们不一样吗?

    最佳答案

    终止的原因有多种:

  • 进程终止调用 return (明确与否)
  • 信号传递后进程终止
  • 信号传递后进程停止。这不是真正的终止,而是在许多情况下需要捕获。

  • 对于 每个这些终端的代码分别是可访问的:
  • 返回值(仅低八位)
  • 信号号
  • 信号号
  • 关于c++ - 应用程序的返回码是一个 int16_t?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65611811/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com