From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.sysutils.supervision.general/2569 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: sysinit@yandex.com Newsgroups: gmane.comp.sysutils.supervision.general Subject: race condition in killall Date: Sun, 5 May 2019 03:55:51 +0200 Message-ID: <20190505015551.GF2595@panda> References: <20190317132532.GA22622@CasperVector> <20190317153002.52c28cf7@dickeberta> <20190319124239.GA26884@CasperVector> <20190319165853.6bb9f44a@flunder> <20190320051439.GA7636@CasperVector> <20190504060704.GA27290@CasperVector> Reply-To: sysinit@yandex.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="65917"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.0 (2018-05-17) To: supervision@List.skarnet.org Original-X-From: supervision-return-2159-gcsg-supervision=m.gmane.org@list.skarnet.org Sun May 05 03:55:57 2019 Return-path: Envelope-to: gcsg-supervision@m.gmane.org Original-Received: from alyss.skarnet.org ([95.142.172.232]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1hN6Nh-000H0v-HD for gcsg-supervision@m.gmane.org; Sun, 05 May 2019 03:55:57 +0200 Original-Received: (qmail 8123 invoked by uid 89); 5 May 2019 01:56:23 -0000 Mailing-List: contact supervision-help@list.skarnet.org; run by ezmlm Original-Sender: Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Original-Received: (qmail 8116 invoked from network); 5 May 2019 01:56:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.com; s=mail; t=1557021354; bh=wIG07tH9cyIUNGAq2k5ZB0LLUzkuGNFlqlUw8jlD6jA=; h=In-Reply-To:Reply-To:Subject:To:From:References:Date:Message-ID; b=BL6zPhVCd7Q91ppw1gWbYIET2UKQue9vZJAr9uALzibykJAV276mF6EukRocO+J3B DkjEpowLNLIa2SN7yncb9RxmbRA1deuOAr9EAz5rlJ4pcIcCaESov3caa83j7ePT8a ZF0+h/WWKlnlS6Y6onCcqxFa2ESVCJVa86cNmmKo= Authentication-Results: mxback7g.mail.yandex.net; dkim=pass header.i=@yandex.com Content-Disposition: inline In-Reply-To: <20190504060704.GA27290@CasperVector> Xref: news.gmane.org gmane.comp.sysutils.supervision.general:2569 Archived-At: > 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: /libexec/rc/bin/kill_all it uses the kvm method to find running processes on the BSDs and the procfs on Linux.