Feature #13677
openpwait -v should decode wait status
0%
Description
At present, pwait -v just prints the return from wait as a hex integer, it'd be nice if it decoded it.
Files
Updated by Ryan England about 1 year ago
- File pwait_screenshot.PNG pwait_screenshot.PNG added
Rich, I have modified the code to return and integer as opposed to hex. Is this what you meant by decode?
Test: Echo terminal PID, pwait -v PID, close terminal. See screenshot for output.
Updated by Joshua M. Clulow about 1 year ago
I suspect Rich probably meant that in addition to printing the numeric value, we could print a string that describes what it means symbolically. For reference, there are a number of macros documented in the wait.h manual page that allow for decoding the status. e.g., you might do something like:
static void maybe_comma(custr_t *) { if (custr_len(cu) != 0) { if (custr_append(cu, ", ") != 0) { err(1, "custr_append"); } } } static custr_t * describe_status(int status) { custr_t *cu; if (custr_alloc(&cu) != 0) { err(1, "custr_alloc"); } if (WIFEXITED(status)) { maybe_comma(cu); if (custr_append_printf(cu, "exited with status %d", WEXITSTATUS(status)) != 0) { err(1, "custr_append_printf"); } } if (WIFSIGNALED(status)) { maybe_comma(cu); if (custr_append_printf(cu, "terminated by signal %d", WTERMSIG(status)) != 0) { err(1, "custr_append_printf"); } if (WCOREDUMP(status)) { maybe_comma(cu); if (custr_append(cu, "dumped core")) { err(1, "custr_append_printf"); } } } return (cu); }
Note that this is an incomplete sketch. You might also consider translating the signal numbers into names as well, say, for WTERMSIG and WSTOPSIG.
Updated by Andy Fiddaman about 1 year ago
When I recently tried to get pwait to show anything other than zero, I was unsuccessful.
Have you had any success there?
Updated by Ryan England about 1 year ago
Andy Fiddaman wrote in #note-4:
When I recently tried to get pwait to show anything other than zero, I was unsuccessful.
Have you had any success there?
Andy, I have NOT been able to get pwait to return anything other than zero either.
Updated by Rich Lowe about 1 year ago
I had seen other values at least once, but I'm struggling to get it now. I guess maybe we should change it to "should work"?
And yes, decoded in the sense that Joshua sketched out. Sorry for being so terse.
Updated by Ryan England about 1 year ago
Shout out to Andy Fiddaman, who created the following code in order to create a zombie process. This was needed in order to get pwait to output something other than zero. The code can be created within a file named zomb.c.
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
void
main(void)
{
if (fork() == 0)
exit(13);
for (;;)
sleep(60);
}
build% ./zomb &
[1] 24936
build% ptree $!
11196 zsched
11340 /sbin/init
11865 /usr/sbin/sshd
9386 /usr/sbin/sshd -R
9388 /usr/sbin/sshd -R
9389 -zsh
24936 ./zomb
24937 <defunct>
build% xxd -s 230 -l4 /proc/24937/psinfo
000000e6: 0000 000d ....
build% pwait -v 24937
24937: terminated, wait status 0x0d00