On 10/28/2013 09:29 PM, Igor Podlesny wrote:
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 |  5 +++++
  2 files changed, 32 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..99bd979 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,9 @@ 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
+.OP -p
+Show the corresponding in-container PID(s).

Have you seen the result of this? We do not need square brackets around -p here.

Also, please reply in that thread, don't create a new one (hint: git send-email --in-reply-to

And add v2 (or v3) to the subject, and a short one-liner in the description body telling why it is v2
+.TP
  .B -
  Read PID(s) from the standard input.
  .SH EXIT STATUS

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to