<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aguerson</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aguerson"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Aguerson"/>
	<updated>2026-04-30T02:55:51Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Processes_scope_and_visibility&amp;diff=13430</id>
		<title>Processes scope and visibility</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Processes_scope_and_visibility&amp;diff=13430"/>
		<updated>2013-02-22T15:50:51Z</updated>

		<summary type="html">&lt;p&gt;Aguerson: vzprocps-perl&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This [[:Category:HOWTO|HOWTO]] shows how OpenVZ [[hardware node]]&lt;br /&gt;
administrator can see a processes belonging to the host system only, or to a&lt;br /&gt;
particular [[container]].&lt;br /&gt;
&lt;br /&gt;
== Problem ==&lt;br /&gt;
From [[CT0]] one can see all the processes running on the system; that&lt;br /&gt;
includes all the processes of all [[container]]s and the processes of the&lt;br /&gt;
[[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&lt;br /&gt;
particular container.&lt;br /&gt;
&lt;br /&gt;
There are many ways to achieve it.&lt;br /&gt;
&lt;br /&gt;
== Solutions ==&lt;br /&gt;
&lt;br /&gt;
=== Hide container processes from host completely ===&lt;br /&gt;
&lt;br /&gt;
It is possible to hide other CT's processes from [[CT0]]. For this just enable kernel.pid_ns_hide_child sysctl parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sysctl -w 'kernel.pid_ns_hide_child=1'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and restart all containers. To make setting permanent put into /etc/sysctl.conf following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel.pid_ns_hide_child=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After this ps or htop or top do not show anymore other container processes.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Poor man's vzps in bash&amp;quot; ===&lt;br /&gt;
Use the following script by aistis, broken by [[User:Kir|Kir]], fixed by [[User:Hvdkamer|Hvdkamer]].&lt;br /&gt;
&lt;br /&gt;
First argument is CT ID (0 for the host system), all the remaining arguments are passed to &amp;lt;code&amp;gt;ps(1)&amp;lt;/code&amp;gt; utility.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# Usage: ./ovzps CTID [ps flags ...]&lt;br /&gt;
&lt;br /&gt;
function find_container_pids(){&lt;br /&gt;
       local pid&lt;br /&gt;
       local myctid=$1&lt;br /&gt;
       local ctpids=&lt;br /&gt;
&lt;br /&gt;
       for pid in $ALLPIDS; do&lt;br /&gt;
               [ -f /proc/$pid/status ] || continue&lt;br /&gt;
               ctid=`grep envID /proc/$pid/status | awk -F: '{print $2}'`&lt;br /&gt;
               if [ ${ctid} = ${myctid} ]; then&lt;br /&gt;
                       ctpids=&amp;quot;$ctpids $pid&amp;quot;&lt;br /&gt;
               fi&lt;br /&gt;
       done&lt;br /&gt;
       echo &amp;quot;$ctpids&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
ALLPIDS=`ps -A -o pid --no-headers`&lt;br /&gt;
CTPIDS=`find_container_pids $1`&lt;br /&gt;
shift&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;${CTPIDS}&amp;quot; ]; then&lt;br /&gt;
        ps $* -p $CTPIDS&lt;br /&gt;
else&lt;br /&gt;
        exit 0&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A faster version:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
# Usage: ovzps &amp;lt;CTID&amp;gt; [ps flags ...]&lt;br /&gt;
&lt;br /&gt;
ctid=${1:-0}&lt;br /&gt;
shift&lt;br /&gt;
&lt;br /&gt;
ps $* -p $(grep -l &amp;quot;^envID:[[:space:]]*$ctid\$&amp;quot; /proc/[0-9]*/status | &lt;br /&gt;
	sed -e 's=/proc/\([0-9]*\)/.*=\1=')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Use vzprocps tools ===&lt;br /&gt;
Take &amp;lt;code&amp;gt;vzprocps&amp;lt;/code&amp;gt; tools from http://download.openvz.org/contrib/utils/.&lt;br /&gt;
These are usual &amp;lt;code&amp;gt;ps&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;top&amp;lt;/code&amp;gt; utilities (named &amp;lt;code&amp;gt;vztop&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;vzps&amp;lt;/code&amp;gt; to not conflict with the standard ones) with an &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; option added. You can use &amp;lt;code&amp;gt;-E &amp;lt;i&amp;gt;CTID&amp;lt;/i&amp;gt;&amp;lt;/code&amp;gt; option to limit the output to the selected CTID (use 0 for the host system), or just &amp;lt;code&amp;gt;-E&amp;lt;/code&amp;gt; without an argument to just add CTID column to output.&lt;br /&gt;
&lt;br /&gt;
=== Use vzprocps-perl tools ===&lt;br /&gt;
Take &amp;lt;code&amp;gt;vzprocps-perl&amp;lt;/code&amp;gt; tools from http://sourceforge.net/p/vzprocpsperl/wiki/vzprocps-perl/.&lt;br /&gt;
Write in Perl with basics functions. &lt;br /&gt;
Can be used in x86_64 architecture. &lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* {{Forum|836}}&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Aguerson</name></author>
		
	</entry>
</feed>