[Devel] [PATCH] vzpid: option "-p" added to show internal PID(s)

Kir Kolyshkin kir at openvz.org
Mon Oct 28 11:10:17 PDT 2013


On 10/28/2013 10:24 AM, Igor Podlesny wrote:
> New command line option '-p' means show corresponding internal PID(s) as well:
>
> 	# vzpid -p 2129
> 	Pid     CT/Pid  CTID    Name
> 	2129    333     1020    mysqld
> ---
>   bin/vzpid.in   | 33 +++++++++++++++++++++++++++------
>   man/vzpid.8.in |  6 +++++-
>   2 files changed, 32 insertions(+), 7 deletions(-)
>
> diff --git a/bin/vzpid.in b/bin/vzpid.in
> index 36e672b..8a65f2a 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 == "'"$veidmark"'") {veid = $2}
> -END {printf("%d\t%s\t%s\n", pid, veid, name)}
> -	' <"/proc/$pid/status"
> +($1 == "'"$vpidmark"'") {vpid = $2}
> +'"$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..35ab71d 100644
> --- a/man/vzpid.8.in
> +++ b/man/vzpid.8.in
> @@ -3,8 +3,9 @@
>   vzpid \- display the CT ID given the process ID
>   .SH SYNOPSIS
>   .SY vzpid
> -\fIpid\fR [...]
> +[-p] \fIpid\fR [...]

option name should be bold, and since we're using .SY here, it's as easy as

.OP -p


>   .SY vzpid
> +[-p]
ditto
>   .B -
>   .YS
>   .SH DESCRIPTION
> @@ -15,6 +16,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
> +.B -p
> +Show corresponding internal PID(s).

I'm not sure the word "internal" is good here. Maybe "in-container" 
works better.
s/corresponding/the corresponding/

> +.TP
>   .B -
>   Read PID(s) from the standard input.
>   .SH EXIT STATUS




More information about the Devel mailing list