race condition in killall

From: <sysinit_at_yandex.com>
Date: Sun, 5 May 2019 03:55:51 +0200

> pkill(1), killall(1) and killall5(8) all retrieve a process list and
> kill them one by one, instead of calling kill(-1, signal), so a race
> condition can happen thats let some process escape the final SIGKILL.

interesting. i have not considered this at all.
looks like kill( -1, sig ) from process #1 ensures correctnes here
in a cheap and simple way.
so splitting stage 3 into 2 parts seems to be a good approach.

> Since pkill(1) and killall(1) use regex matching, the probability for
> the race can be significantly larger.

since they do more work to select processes and hence need more time when
iterating the PID dirs in the procfs ?
though i doubt they use any matching at all when tasked with killing all
processes and probably behave like the killall5 utility in this situation.

OpenRC also provides a tool for that task btw:

it uses the kvm method to find running processes on the BSDs and the procfs
on Linux.
Received on Sun May 05 2019 - 01:55:51 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC