[Devel] [PATCH] vzpid: new option "-p" to show in-container PID(s)

Igor Podlesny openvz at poige.ru
Mon Oct 28 22:54:46 PDT 2013


New command line option "-p" means show additionaly the corresponding
in-container PID(s), note CT/Pid column in the following example:

	# vzpid -p 2129
	Pid     CT/Pid  CTID    Name
	2129    333     1020    mysqld
---
 bin/vzpid.in   | 33 +++++++++++++++++++++++++++------
 man/vzpid.8.in |  6 ++++++
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/bin/vzpid.in b/bin/vzpid.in
index 36e672b..e148236 100755
--- a/bin/vzpid.in
+++ b/bin/vzpid.in
@@ -17,31 +17,52 @@
 #
 veidmark='envID:'
 namemark='Name:'
+vpidmark='VPid:'
+showCTPID=0
+opShowCTPID='END {printf("%d\t%d\t%s\t%s\n", pid, vpid, veid, name)}'
+opShowDef='END {printf("%d\t%s\t%s\n", pid, veid, name)}'
 
 usage()
 {
-	echo 'Usage: vzpid <pid> ...'
-	echo '       vzpid -'
+	echo 'Usage: vzpid [-p] <pid> ...'
+	echo '       vzpid [-p] -'
 }
 
 header()
 {
-	printf '%s\t%s\t%s\n' 'Pid' 'CTID' 'Name'
+	if [ "$showCTPID" -ne 0 ]; then
+		printf '%s\t%s\t%s\t%s\n' 'Pid' 'CT/Pid' 'CTID' 'Name'
+	else
+		printf '%s\t%s\t%s\n' 'Pid' 'CTID' 'Name'
+	fi
 }
 
 getveid()
 {
+	local opShow
 	local pid="$1"
 
 	[ -f "/proc/$pid/status" ] || return
+
+	if [ "$showCTPID" -ne 0 ]; then
+		opShow="$opShowCTPID"
+	else
+		opShow="$opShowDef"
+	fi
+
 	awk -v "pid=$pid" '
-BEGIN {veid=0; name=""}
+BEGIN {veid=0; name=""; vpid=0}
 ($1 == "'"$namemark"'") {name = $2}
+($1 == "'"$vpidmark"'") {vpid = $2}
 ($1 == "'"$veidmark"'") {veid = $2}
-END {printf("%d\t%s\t%s\n", pid, veid, name)}
-	' <"/proc/$pid/status"
+'"$opShow" <"/proc/$pid/status"
 }
 
+if [ "$1" = '-p' ]; then
+	showCTPID=1
+	shift
+fi
+
 if [ $# -eq 0 ]; then
 	usage >&2
 	exit 1
diff --git a/man/vzpid.8.in b/man/vzpid.8.in
index 18018ca..7311b18 100644
--- a/man/vzpid.8.in
+++ b/man/vzpid.8.in
@@ -3,8 +3,10 @@
 vzpid \- display the CT ID given the process ID
 .SH SYNOPSIS
 .SY vzpid
+.OP -p
 \fIpid\fR [...]
 .SY vzpid
+.OP -p
 .B -
 .YS
 .SH DESCRIPTION
@@ -15,6 +17,10 @@ This script displays the CT ID the process with the given \fIpid\fR belongs to.
 The \fIpid\fR of the process to display the CT ID of. Can be specified
 multiple times.
 .TP
+.TP
+.I -p
+Show the corresponding in-container PID(s).
+.TP
 .B -
 Read PID(s) from the standard input.
 .SH EXIT STATUS
-- 
1.8.1.2




More information about the Devel mailing list