From e0b100caee0bc55f9654b834ebe4f952e85daee5 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Fri, 1 Oct 2004 11:00:15 +0000 Subject: [PATCH] use more efficient ways to detect number of processes in a context (access /proc/virtual/... information instead of executing vps) git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1717 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/scripts/functions | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/util-vserver/scripts/functions b/util-vserver/scripts/functions index 3779584..66c3bd3 100644 --- a/util-vserver/scripts/functions +++ b/util-vserver/scripts/functions @@ -391,6 +391,24 @@ function getAllVservers eval $1='( "${_tmp[@]}" )' } +## Usage: _getProcNumberCount +function _getProcNumberCount +{ + local var=$2 + local procnr_cnt=0 + + # Use /proc/virtual from kernel 2.6 when possible + if test -d "/proc/virtual"; then + set -- $($_GREP '^PROC:' "/proc/virtual/$1/limit" 2>/dev/null) + procnr_cnt=$2 + else + procnr_cnt=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$_ctx" | $_WC -l ) + fi + + let procnr_cnt=procnr_cnt+0 + eval $var=\$procnr_cnt +} + ## Usage: getVserverCtx [ []] ## Returns: 0 iff vserver is running function getVserverStatus @@ -402,8 +420,8 @@ function getVserverStatus eval "$2"=\$_ctx test "$3" || return 0 - local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$_ctx" | $_WC -l ) - let _tmp=_tmp+0 + local _tmp + _getProcNumberCount "$_ctx" _tmp eval "$3"=\$_tmp if test "$_tmp" = 0; then @@ -418,7 +436,8 @@ function getVserverStatus ## Usage: isCtxRunning function isCtxRunning { - local _tmp=$($_VPS ax | $_AWK '{print $2}' | $_GREP -x "$1" | $_WC -l ) + local _tmp + _getProcNumberCount "$1" _tmp test $_tmp -gt 0 } -- 1.8.1.5