writing to closed stdout (II): exit status
kdevel
kdevel at vogtner.de
Tue Dec 17 21:21:09 UTC 2024
On Monday, 16 December 2024 at 09:33:12 UTC, Kagamin wrote:
> On Sunday, 15 December 2024 at 19:41:00 UTC, kdevel wrote:
>> On Sunday, 15 December 2024 at 17:16:11 UTC, Paul Backus wrote:
>>> It's possible to get the full exit status from `waitid` [3],
>>
>> Actually not on my linux machine:
>
> Try ssi_status from signalfd.
Like this?
```c
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/signalfd.h>
int main ()
{
int rc = fork ();
assert (rc != -1);
if (rc == 0) { /* child */
sleep (1);
_exit (-1);
}
else {
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
int sfd = signalfd (-1, &mask, 0);
assert (sfd != -1);
rc = sigprocmask (SIG_BLOCK, &mask, 0);
assert (rc != -1);
struct signalfd_siginfo sfds;
ssize_t s = read (sfd, &sfds, sizeof sfds);
assert (s == sizeof sfds);
printf ("%x\n", sfds.ssi_status);
}
return 0;
}
```
More information about the Digitalmars-d
mailing list