From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 629CF1382C5 for ; Fri, 5 Feb 2021 14:00:13 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 00782E091B; Fri, 5 Feb 2021 14:00:08 +0000 (UTC) Received: from pmta21.teksavvy.com (pmta21.teksavvy.com [76.10.157.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id AA480E08E0 for ; Fri, 5 Feb 2021 14:00:07 +0000 (UTC) IronPort-SDR: 1vkkmWDH3uepGX7TPTN/VFX0o8t/P5cQDQ1AfxVIBINmwV/r1PkwsiX/263XZrpM5r9rutOjSq 5oviajVpTU7w== X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2FEGQB9Th1g/1Z9oWxgAh0BAQEBCQE?= =?us-ascii?q?SAQUFAUAHgUiDd2uIdIRQhkABgXkdAzcBgzuYUAsBAQEBAQEBAQE1AQIEAQG?= =?us-ascii?q?ERAQCAoICJjgTAgMBAQsBAQEFAQEBAQEGBAIChluGUAEBAQECATocKAsLGBY?= =?us-ascii?q?GEhBHGYYNILAodIE0hVmFCIE4jUNBP4ECP4QqPoUGBQiFJASDVYIxQDKPcBG?= =?us-ascii?q?NIptrCoJ6gRkGmwaDLpAPJI9BtkSBeoF7fQiDJFAZDVeNVheORSYwNwIGCgE?= =?us-ascii?q?BAwlXAYh3ERuCGgEB?= X-IPAS-Result: =?us-ascii?q?A2FEGQB9Th1g/1Z9oWxgAh0BAQEBCQESAQUFAUAHgUiDd?= =?us-ascii?q?2uIdIRQhkABgXkdAzcBgzuYUAsBAQEBAQEBAQE1AQIEAQGERAQCAoICJjgTA?= =?us-ascii?q?gMBAQsBAQEFAQEBAQEGBAIChluGUAEBAQECATocKAsLGBYGEhBHGYYNILAod?= =?us-ascii?q?IE0hVmFCIE4jUNBP4ECP4QqPoUGBQiFJASDVYIxQDKPcBGNIptrCoJ6gRkGm?= =?us-ascii?q?waDLpAPJI9BtkSBeoF7fQiDJFAZDVeNVheORSYwNwIGCgEBAwlXAYh3ERuCG?= =?us-ascii?q?gEB?= X-IronPort-AV: E=Sophos;i="5.81,155,1610427600"; d="scan'208";a="153978255" Received: from 108-161-125-86.dsl.teksavvy.com (HELO waltdnes.org) ([108.161.125.86]) by smtp12.teksavvy.com with SMTP; 05 Feb 2021 09:00:06 -0500 Received: by waltdnes.org (sSMTP sendmail emulation); Fri, 05 Feb 2021 14:00:06 -0500 From: "Walter Dnes" Date: Fri, 5 Feb 2021 14:00:05 -0500 To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] HOWTO: Freezing/unfreezing (groups of) processes Message-ID: References: Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Archives-Salt: 0371b97e-fe50-412d-9e2a-578166407ab0 X-Archives-Hash: 29202289525e4f6c1be1d8b2f8a79a20 On Fri, Feb 05, 2021 at 03:46:45AM -0500, Andrew Udvare wrote > > > On 2021-02-05, at 02:45, Walter Dnes wrote: > > > > done < /dev/shm/temp.txt > > You don't need to write a temporary file. You can pipe this directly into the while loop: > > while read > do > ... > done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop) I wasn't aware of the "< <" construct. Nice > Also to avoid the second grep in Bash at least: > > grep "[${1:0:1}]${1:1}" That causes some feedback about backgrounded processes. In addition to your avoiding-the-temp-file trick, I also realized that if I read the first 3 items of each line, I can use the 2nd parameter directly without an intermediate assignment to an array. The latest version of my scripts are... ======================= pstop ======================= while read userid pid rest_of_line do kill -SIGSTOP ${pid} done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pstop) ======================= pcont ======================= #!/bin/bash while read userid pid rest_of_line do kill -SIGCONT ${pid} done < <(ps -ef | grep ${1} | grep -v "grep ${1}" | grep -v pcont) ===================================================== In the course of experimentation, I've made versions that killed critical processes, requiring a reboot. {ALT}{SYSRQ} to the rescue . I'll stick with stuff that works. -- Walter Dnes I don't run "desktop environments"; I run useful applications