From owner-freebsd-questions@FreeBSD.ORG Tue Sep 26 19:22:56 2006 Return-Path: X-Original-To: questions@freebsd.org Delivered-To: freebsd-questions@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C4F5D16A417 for ; Tue, 26 Sep 2006 19:22:56 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.FreeBSD.org (Postfix) with ESMTP id A805043D79 for ; Tue, 26 Sep 2006 19:22:41 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.pc (host5.bedc.ondsl.gr [62.103.39.229]) (authenticated bits=128) by igloo.linux.gr (8.13.8/8.13.8/Debian-2) with ESMTP id k8QJMLUT003301 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 26 Sep 2006 22:22:29 +0300 Received: from gothmog.pc (gothmog [127.0.0.1]) by gothmog.pc (8.13.8/8.13.8) with ESMTP id k8QJMrqX003195; Tue, 26 Sep 2006 22:22:53 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.pc (8.13.8/8.13.8/Submit) id k8QJMqcT003194; Tue, 26 Sep 2006 22:22:52 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Tue, 26 Sep 2006 22:22:52 +0300 From: Giorgos Keramidas To: Brett Glass Message-ID: <20060926192252.GG1863@gothmog.pc> References: <7.0.1.0.2.20060926090533.083a2a88@lariat.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7.0.1.0.2.20060926090533.083a2a88@lariat.net> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (score=-2.656, required 5, AWL -0.26, BAYES_00 -2.60, DNS_FROM_RFC_ABUSE 0.20, UNPARSEABLE_RELAY 0.00) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: questions@freebsd.org Subject: Re: Best way to "renice" a process by name? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Sep 2006 19:22:56 -0000 On 2006-09-26 09:32, Brett Glass wrote: > I'm working with a machine that's operating as a NAT router and > recursive DNS resolver and is also running the Squid disk cache. > Squid, in turn, spawns the "diskd" daemon, which does disk accesses on > behalf of Squid. When Squid spawns diskd, it gives it a priority level > 6 greater than itself. In other words, if Squid is launched normally, > it gets a priority of 2 (normal) while diskd gets a priority of -4 > (very high). > > Unfortunately, diskd is not an efficient user of CPU (it seems to be > polling for I/O completion) and is starving other processes on the > machine (for example, natd) which need to operate in near real time. > > I'd like to keep diskd running on that machine, because having disk > access done by a separate process is very efficient -- even more so if > the system uses SMP. But I need to re-prioritize Squid and diskd to > keep the rest of the machine functional. In particular, I'd like to > nice Squid down by 1 (so that natd and named have priority over it) > and have diskd run at standard priority (so that it can't starve other > processes). This will keep diskd at a higher priority than Squid > itself, which in turn will hopefully prevent message queues from > overflowing. > > Reducing Squid's priority is simple; I can just edit the script that > starts Squid so that /usr/bin/nice is used to invoke it. But taming > diskd is more difficult, because diskd is a child process of Squid. I > have to make sure it has started (which may require a delay loop), > find out its PID, and then "renice" it by whatever increment is > required to get it to the system's standard priority (2 by > convention). Is there a "renice by name" utility for FreeBSD (sort of > an equivalent of "killall")? I could gin one up, but since this seems > like something that people would want to do frequently, find it hard > to believe that someone hasn't already written one. Maybe something like this helps? $ echo renice -n +10 -p `echo \`pgrep httpd\` | sed -e 's/ /,/g'` renice -n +10 -p 1023,656,655,654,653,652,610 $ There is always a fair chance you might attempt to renice a process which just happened to die, but this should be ok, unless you start seeing PIDs being recycled too fast :)