init problems (feature or bug?)
Luciano Miguel Ferreira Rocha
strange at nsk.no-ip.org
Tue Jan 9 13:45:08 PST 2007
On Mon, Jan 08, 2007 at 02:13:51PM +0100, Dirk Clemens wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I have found an init problem:
>
> - --------------- Example 1 ---------------
>
>
> - --- file /etc/inittab ---
> ::shutdown:/etc/halt
> - --- end --
>
> - --- file /etc/halt ---
> kill -TERM -1
> sleep 5
> kill -KILL -1
> sleep 5
> umount -a
> - --- end --
>
> After the first kill, /etc/halt will also be terminated.
> The second kill will never be executed.
>
Is that kill a shell internal command or an external command? If the
later, then it is expected for it to signal all processes except itself
(on Linux) and init.
>
> - --------------- Example 2 ---------------
>
> - --- file /etc/inittab ---
> ::shutdown:/etc/halt1
> ::shutdown:/etc/halt2
> - --- end --
>
> - --- file /etc/halt1 ---
> kill -TERM -1
> sleep 5
> kill -KILL -1
> sleep 5
> - --- end --
>
> - --- file /etc/halt2 ---
> sleep 20
> do_something
> - --- end --
>
> After the first kill /etc/halt2 is started and both
> /etc/halt1 and /etc/halt2 runs at same time.
>
>
> - -----------------
>
> The reason is: init creates a sub process (#A) and that
> sub process create a new sub process (#B) which will execute
> the code or script. And #A is not roust against signals.
#A can *never* be robust against -KILL.
> So if the script in #B uses 'kill -TERM -1', #A will be
> killed and init thinks, that the job has finished
>
> In example 1 init thinks that shutdown is done
> and kills itself all other processes.
>
> In example 2 init thinks that halt1 is done and
> starts halt2, so that both runs together.
>
> I have the same effects when using bash internal kill
> or busybox kill.
I have no problems with something like this:
killall5 -15
sleep 1
killall5 -9
And the killall5 (I use bash) is:
#!/bin/sh
sig="${1:--15}"
pids=(/proc/[0-9]*)
for pe in ${pids[*]}; do
# disappeared
[ -d $pe ] || continue
# kernel thread
[ -f $pe/exe ] || continue
# p = pid
p="${pe##*/}"
# init
[ "$p" -eq "1" ] && continue
# parent
[ "$p" -eq "$PPID" ] && continue
# self
[ "$p" -eq "$$" ] && continue
kill $sig $p
done
--
lfr
0/0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://busybox.net/lists/busybox/attachments/20070109/abce596f/attachment.pgp
More information about the busybox
mailing list