[buildd-tools-devel] Bug#606162: [PATCH] 15killprocs: Don’t run /bin/readlink for every process
Anders Kaseorg
andersk at ksplice.com
Mon Dec 6 22:39:24 UTC 2010
Package: schroot
Version: 1.4.15-1
Tags: patch
/etc/schroot/setup.d/15killprocs has a loop that runs ‘readlink
/proc/"$pid"/root’ for every process in the system. I have a system with
thousands of processes, and this loop makes schroot take about a minute to
close a chroot. I changed it to use the builtin -ef operator; now it
takes about a second.
Anders
-- 8< --
From: Anders Kaseorg <andersk at ksplice.com>
Subject: [PATCH] setup.d: 15killprocs: Don’t run /bin/readlink for every process
On a system with thousands of processes, this loop took about a minute;
now it takes about a second.
Signed-off-by: Anders Kaseorg <andersk at ksplice.com>
---
etc/setup.d/15killprocs | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/etc/setup.d/15killprocs b/etc/setup.d/15killprocs
index 88b9320..619035e 100755
--- a/etc/setup.d/15killprocs
+++ b/etc/setup.d/15killprocs
@@ -40,8 +40,7 @@ do_kill_all()
info "Killing processes run inside $1"
ls /proc | egrep '^[[:digit:]]+$' |
while read pid; do
- root=$(readlink /proc/"$pid"/root || true)
- if [ "$root" = "$1" ]; then
+ if [ /proc/"$pid"/root -ef "$1" ]; then
exe=$(readlink /proc/"$pid"/exe || true)
info "Killing left-over pid $pid (${exe##$1})"
info " Sending SIGTERM to pid $pid"
--
1.7.3.3
More information about the Buildd-tools-devel
mailing list