advice please? Is there a known issue with SIGINT for scripts?

Denys Vlasenko vda.linux at googlemail.com
Wed Feb 9 14:55:33 UTC 2011


On Wed, Feb 9, 2011 at 3:20 PM, David Collier
<from_busybox_maillist at dexdyne.com> wrote:
>> > < I used killall about 4 secs into this sleep >
>> > < notice the SIGINT is ignored until sleep is over >
>>
>> This "delayed" trap execution is intended:
>>
>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.
>> html
>>
>> When a signal for which a trap has been set is received while the
>> shell is waiting for the completion of a utility executing a
>> foreground command, the trap associated with that signal shall not
>> be executed until after the foreground command has completed.
>
> No problem - it's something to be taken into account - I didn't realise
> it would do that... though in truth it would be hard to interrupt a
> running command and return to it, so I can see why it's defined that way.

Signals are per-process. When shell receives a signal, its child (the running
process) does not. Therefore shell can in theory be coded to execute traps
at once. It's just not what standard says it should do.

> It means one is better off doing 100 repeats of a 1-second sleep, rather
> than a single sleep, if you want the process to respond when asked to
> shut down.

There is a way around that:

sleep 100 &
wait

wait builtin *is* interruptible by signals, therefore traps will execute
at once, not when backgrounded sleep exits.

-- 
vda


More information about the busybox mailing list