Why does wait() set status to 256 instead of the -1 exit status of the forked process?

前端 未结 5 1386
渐次进展
渐次进展 2020-12-01 21:36

I\'m trying to return an integer value from a child process.

However, if I use exit(1) i get 256 as the output. exit(-1)

5条回答
  •  一向
    一向 (楼主)
    2020-12-01 21:44

    Use WEXITSTATUS() to read the correct exit status of child

    Pass the status returned by waitpid() or wait()

    e.g.:

    int cstatus;
    wait(&cstatus);
    printf("Child exit status : %d\n", WEXITSTATUS(cstatus));
    

提交回复
热议问题