[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: the exquisite pain of signal handling in shell scripts
From: |
Ralph Corderoy |
Subject: |
Re: the exquisite pain of signal handling in shell scripts |
Date: |
Sat, 09 May 2020 16:47:33 +0100 |
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 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.
Scripts shouldn't use exit $n where n>=126 unless it's for one of the
reasons given in
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_21_18
which includes n>128 for signal n-128.
--
Cheers, Ralph.