busybox/shell/ash_doc.txt
<<
>>
Prefs
   1        Wait + signals
   2
   3We had some bugs here which are hard to test in testsuite.
   4
   5Bug 1280 (http://busybox.net/bugs/view.php?id=1280):
   6was misbehaving in interactive ash. Correct behavior:
   7
   8$ sleep 20 &
   9$ wait
  10^C
  11$ wait
  12^C
  13$ wait
  14^C
  15...
  16
  17
  18Bug 1984 (http://busybox.net/bugs/view.php?id=1984):
  19traps were not triggering:
  20
  21trap_handler_usr () {
  22    echo trap usr
  23}
  24trap_handler_int () {
  25    echo trap int
  26}
  27trap trap_handler_usr USR1
  28trap trap_handler_int INT
  29sleep 3600 &
  30echo "Please do: kill -USR1 $$"
  31echo "or: kill -INT $$"
  32while true; do wait; echo wait interrupted; done
  33
  34
  35Bug 189 (https://bugs.busybox.net/show_bug.cgi?id=189)
  36
  37func() {
  38    sleep 1
  39}
  40while (true); do
  41    func
  42    echo Looping
  43done
  44
  45^C was observed to make ash processes geometrically multiply (!) instead
  46of exiting. (true) in subshell does not seem to matter, as another user
  47reports the same with:
  48
  49trap "echo USR1" USR1
  50while true; do
  51    echo Sleeping
  52    sleep 5
  53done
  54
  55Compat note.
  56Bash version 3.2.0(1) exits this script at the receipt of SIGINT
  57_only_ if it had two last children die from it.
  58The following trace was obtained while periodically running
  59"killall -SIGINT sleep; sleep 0.1; kill -SIGINT <bash_PID>":
  60
  6123:48:32.376707 clone(...) = 13528
  6223:48:32.388706 waitpid(-1, 0xffc832ec, 0) = ? ERESTARTSYS (To be restarted)
  6323:48:32.459761 --- SIGINT (Interrupt) @ 0 (0) ---
  64    kill -SIGINT <bash_PID> is ignored, back to waiting:
  6523:48:32.463706 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 13528
  66    sleep exited with 0
  6723:48:37.377557 --- SIGCHLD (Child exited) @ 0 (0) ---
  6823:48:37.378451 clone(...) = 13538
  6923:48:37.390708 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 13538
  70    sleep was killed by "killall -SIGINT sleep"
  7123:48:38.523944 --- SIGCHLD (Child exited) @ 0 (0) ---
  7223:48:38.524861 clone(...) = 13542
  7323:48:38.538706 waitpid(-1, 0xffc832ec, 0) = ? ERESTARTSYS (To be restarted)
  7423:48:38.624761 --- SIGINT (Interrupt) @ 0 (0) ---
  75    kill -SIGINT <bash_PID> is ignored, back to waiting:
  7623:48:38.628706 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 13542
  77    sleep exited with 0
  7823:48:43.525674 --- SIGCHLD (Child exited) @ 0 (0) ---
  7923:48:43.526563 clone(...) = 13545
  8023:48:43.538709 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 13545
  81    sleep was killed by "killall -SIGINT sleep"
  8223:48:44.466848 --- SIGCHLD (Child exited) @ 0 (0) ---
  8323:48:44.467735 clone(...) = 13549
  8423:48:44.481706 waitpid(-1, 0xffc832ec, 0) = ? ERESTARTSYS (To be restarted)
  8523:48:44.567757 --- SIGINT (Interrupt) @ 0 (0) ---
  86    kill -SIGINT <bash_PID> is ignored, back to waiting:
  8723:48:44.571706 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 13549
  88    sleep exited with 0
  8923:48:49.468553 --- SIGCHLD (Child exited) @ 0 (0) ---
  9023:48:49.469445 clone(...) = 13551
  9123:48:49.481708 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 13551
  92    sleep was killed by "killall -SIGINT sleep"
  9323:48:50.515837 --- SIGCHLD (Child exited) @ 0 (0) ---
  9423:48:50.516718 clone(...) = 13555
  9523:48:50.530706 waitpid(-1, 0xffc832ec, 0) = ? ERESTARTSYS (To be restarted)
  9623:48:50.615761 --- SIGINT (Interrupt) @ 0 (0) ---
  97    kill -SIGINT <bash_PID> is ignored, back to waiting:
  9823:48:50.619705 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 13555
  99    sleep was killed by "killall -SIGINT sleep".
 100    This is the second one in a row. Kill ourself:
 10123:48:51.504604 kill(13515, SIGINT)     = 0
 10223:48:51.504689 --- SIGINT (Interrupt) @ 0 (0) ---
 10323:48:51.504915 +++ killed by SIGINT +++
 104
 105As long as there is at least one "sleep 5" which exited successfully
 106(not killed by SIGINT), bash continues. This is not documented anywhere
 107AFAIKS.
 108
 109Why keyboard ^C acts differently?
 110
 11100:08:07.655985 clone(...) = 14270
 11200:08:07.669707 waitpid(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0) = 14270
 11300:08:12.656872 --- SIGCHLD (Child exited) @ 0 (0) ---
 11400:08:12.657743 clone(...) = 14273
 11500:08:12.671708 waitpid(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGINT}], 0) = 14273
 11600:08:13.810778 --- SIGINT (Interrupt) @ 0 (0) ---
 11700:08:13.818705 kill(14269, SIGINT)     = 0
 11800:08:13.820103 --- SIGINT (Interrupt) @ 0 (0) ---
 11900:08:13.820925 +++ killed by SIGINT +++
 120
 121Perhaps because at the moment bash got SIGINT it had no children?
 122(it did not manage to spawn new sleep yet, see the trace)
 123