简体   繁体   English

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

[英]how to use waitpid() to get the status of child process?

Im trying to get the status of child process. 我正在尝试获取子进程的状态。 for example, when I run "adjsafkl" which is a not exist command, the system print "WRONG", but when I run "cp sssa" which the folder is not exist either, but the system will not mark this command as WRONG. 例如,当我运行不存在的命令“ adjsafkl”时,系统将打印“ WRONG”,但是当我运行也不存在该文件夹的“ cp sssa”时,系统将不会将此命令标记为WRONG。 I wonder is there anyway to fix this error? 我不知道是否有解决此错误的方法?

You may check for WEXITSTATUS after WIFEXITED: 您可以在WIFEXITED之后检查WEXITSTATUS:

WIFEXITED: returns true if the child terminated normally, that is, by calling exit(3) or _exit(2), or by returning from main(). WIFEXITED:如果子项正常终止(即通过调用exit(3)或_exit(2)或从main()返回),则返回true。

WEXITSTATUS: returns the exit status of the child. WEXITSTATUS:返回子项的退出状态。 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(). 它由状态参数的最低有效8位组成,该状态参数的子级是在调用exit(3)或_exit(2)时指定的,或者是main()中return语句的参数。 This macro should only be employed if WIFEXITED returned true. 仅当WIFEXITED返回true时才应使用此宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM