简体   繁体   中英

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. I wonder is there anyway to fix this error?

You may check for WEXITSTATUS after WIFEXITED:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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