gpt4 book ai didi

c++ - 如何使用 waitpid() 获取子进程的状态?

转载 作者:行者123 更新时间:2023-11-28 00:11:18 27 4
gpt4 key购买 nike

我正在尝试获取子进程的状态。例如,当我运行不存在的命令“adjsafkl”时,系统打印“WRONG”,但是当我运行文件夹也不存在的“cp sssa”时,系统不会将此命令标记为错误。我想知道是否有办法修复此错误?

最佳答案

您可以在 WIFEXITED 之后检查 WEXITSTATUS:

WIFEXITED: returns true if the child terminated normally, that is, by calling exit(3) or _exit(2), or by returning from main().

WEXITSTATUS: returns the exit status of the child. This consists of the least significant 8 bits of the status argument that the child specified in a call to exit(3) or _exit(2) or as the argument for a return statement in main(). This macro should only be employed if WIFEXITED returned true.

关于c++ - 如何使用 waitpid() 获取子进程的状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32980213/

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