Linux, where are the return codes stored of system daemons and other processes?

后端 未结 1 1606
攒了一身酷
攒了一身酷 2020-12-22 01:32

How do i know, if a process has completed its execution without any errors? How do i know, if a C++ program has returned success to OS?

If i run it via shell, then i

相关标签:
1条回答
  • 2020-12-22 02:31

    When a process terminates its parent process must acknowledge this using the wait or waitpid function. These functions also return the exit status. After the call to wait or waitpid the process table entry is removed, and the exit status is no longer stored anywhere in the operating system. You should check if the software you use to start the process saves the exit status somewhere.

    If the parent process has not acknowledged that the child has terminated you can read its exit status from the /proc file system: it is the last field in /proc/[pid]/stat. It is stored in the same format that wait returns it, so you have to divide by 256 to get the exit code. Also you probably have to be root.

    0 讨论(0)
提交回复
热议问题