NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: sh won't trap SIGHUP while waiting for jobs



sleep (/bin/sleep) isn't built-in to /bin/sh, so my guess is that
/bin/sleep is catching signal. I think that the 2nd version works
because when you have a loop in sh and sleep for 1 second and there is
time for /bin/sh to catch the signal.

This could be tested by modifying /bin/sleep to catch SIGHUP, printing
a response in the handler and running the first script you posted.

I could be totally wrong, but that's what I'm guessing.

On Thu, Aug 20, 2015 at 5:36 PM, J. Lewis Muir <jlmuir%imca-cat.org@localhost> wrote:
> Hello, NetBSD Users!
>
> I can't get /bin/sh to trap the SIGHUP signal on amd64 NetBSD
> 6.1_STABLE.  Does anyone know why?
>
> Here's a test program exhibiting the behavior:
>
> === test-program ===
> #!/bin/sh
>
> trap 'echo SIGHUP; exit 1' 1
>
> sleep 3600 &
> wait
> ====================
>
> I start the test program in one terminal like this:
>
> $ ./test-program
>
> And then in another terminal, I find the process ID, 354 in this case,
> and send it the SIGHUP signal:
>
> $ kill -1 354
>
> Nothing happens; test-program continues running.
>
> If I replace running sleep in the background and waiting with the
> following:
>
> === test-program-mod ===
> #!/bin/sh
>
> trap 'echo SIGHUP; exit 1' 1
>
> while true; do
>   sleep 1
> done
> ========================
>
> It responds to a SIGHUP and exits.
>
> So, is something wrong with the wait command in /bin/sh?
>
> Thank you!
>
> Lewis


Home | Main Index | Thread Index | Old Index