Difference between revisions of "Processes scope and visibility"

From OpenVZ Virtuozzo Containers Wiki
Jump to: navigation, search
m (Robot: Automated text replacement (-VE0 +CT0))
(VE -> container, CT)
Line 17: Line 17:
 
# Usage: ./ovzps CTID [ps flags ...]
 
# Usage: ./ovzps CTID [ps flags ...]
  
function find_ve_pids(){
+
function find_container_pids(){
 
       local pid
 
       local pid
       local myveid=$1
+
       local myctid=$1
       local vepids=
+
       local ctpids=
  
 
       for pid in $ALLPIDS; do
 
       for pid in $ALLPIDS; do
 
               [ -f /proc/$pid/status ] || continue
 
               [ -f /proc/$pid/status ] || continue
               veid=`grep envID /proc/$pid/status | awk -F: '{print $2}'`
+
               ctid=`grep envID /proc/$pid/status | awk -F: '{print $2}'`
               if [ ${veid} = ${myveid} ]; then
+
               if [ ${ctid} = ${myctid} ]; then
                       vepids="$vepids $pid"
+
                       ctpids="$ctpids $pid"
 
               fi
 
               fi
 
       done
 
       done
       echo "$vepids"
+
       echo "$ctpids"
 
}
 
}
  
 
ALLPIDS=`ps -A -o pid --no-headers`
 
ALLPIDS=`ps -A -o pid --no-headers`
VEPIDS=`find_ve_pids $1`
+
CTPIDS=`find_container_pids $1`
 
shift
 
shift
  
if [ -n "${VEPIDS}" ]; then
+
if [ -n "${CTPIDS}" ]; then
         ps $* -p $VEPIDS
+
         ps $* -p $CTPIDS
 
else
 
else
 
         exit 0
 
         exit 0

Revision as of 12:23, 11 March 2008

This HOWTO shows how OpenVZ hardware node administrator can see a processes belonging to the host system only, or to a particular VE.

Problem

From CT0 one can see all the processes running on the system; that includes all the processes of all VEs and the processes of the host system itself. Sometimes you just want to see the processes from the host system only. Sometimes you just want to see the processes from a particular VE.

There are many ways to achieve it.

Solutions

"Poor man's vzps in bash"

Use the following script by aistis, broken by Kir, fixed by Hvdkamer.

First argument is CT ID (0 for the host system), all the remaining arguments are passed to ps(1) utility.

#!/bin/bash
# Usage: ./ovzps CTID [ps flags ...]

function find_container_pids(){
       local pid
       local myctid=$1
       local ctpids=

       for pid in $ALLPIDS; do
               [ -f /proc/$pid/status ] || continue
               ctid=`grep envID /proc/$pid/status | awk -F: '{print $2}'`
               if [ ${ctid} = ${myctid} ]; then
                       ctpids="$ctpids $pid"
               fi
       done
       echo "$ctpids"
}

ALLPIDS=`ps -A -o pid --no-headers`
CTPIDS=`find_container_pids $1`
shift

if [ -n "${CTPIDS}" ]; then
        ps $* -p $CTPIDS
else
        exit 0
fi

Use vzprocps tools

Take vzprocps tools from http://download.openvz.org/contrib/utils/. These are usual ps and top utilities (named vztop and vzps to not conflict with the standard ones) with an -E option added. You can use -E CTID option to limit the output to the selected CTID (use 0 for the host system), or just -E without an argument to just add CTID column to output.

See also