Question

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 could use $?, however if i am checking the status of a process, initiated by other user, how could i check the status?

Say i started a process in morning, and it got terminated at noon. i have been workign on some other activities till evening, and prior leaving, i would like to check what the processes has returned to OS. how could i acheve that, programatically. Running through syslog would help, but looking for alternatives.

i could run through the OS's process table and read this information, however it sounds a bit complicated for my requirement. Do we have something like syslog, where all errors of processes are recorded?

Any other ways to retrieve errors reported by terminated processes (of other users too)?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top