[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: the exquisite pain of signal handling in shell scripts
From: |
G. Branden Robinson |
Subject: |
Re: the exquisite pain of signal handling in shell scripts |
Date: |
Tue, 5 May 2020 08:20:55 +1000 |
User-agent: |
NeoMutt/20180716 |
At 2020-05-02T10:07:20+0100, Ralph Corderoy wrote:
> Hi Branden,
>
> > It seems like the main difference between our signal handlers is that
> > you do not reset the handler, and rely on exiting with a status
> > greater than 127 to notify the shell that the process was killed with
> > a signal. I'm not sure that is reliable, or supposed to be.
>
> Do you mean distinguish these two cases from a shell script using `$?'?
>
> $ sh -c 'kill $$'; echo $?
> Terminated
> 143
> $ sh -c 'exit 143'; echo $?
> 143
> $
Yes. I suppose, without checking any Unix's implementation details,
that these may differ because the fact that a process has been signaled
could be in a part of the wait-status (which is an int, wider than a
byte) that is not exposed as part of the exit integer.
I suppose that in practice it may be that bit 7 of wstatus is typically
the bit returned by the WIFSIGNALED() macro, but I wouldn't want to
stake my life on it.
The more of the Austin Group's time I see taken up with bizarre
implementation differences in the shell, the more paranoid and less
certain I get about what is reliable.
Regards,
Branden
signature.asc
Description: PGP signature