find container against pid !!

shahzaib

New Member
Jan 27, 2017
3
0
1
30
Hi,

We recently moved to proxmox-4.2 which is under high load & we are seeing some processes causing high usage. If we try to find the container associated to that process PID using vzpid it gives "0" CTID in the output. In older versions, it used to provide accurate CTID but not now. Here is the output of vzpid :


root@vnode:~# vzpid 19662
Pid CTID Name
19662 0 bundle

Is there any changes in newer versions ? Also i can see pct is recommend instead of vz commands now.
 

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
7,870
1,508
164
Hi,

We recently moved to proxmox-4.2 which is under high load & we are seeing some processes causing high usage. If we try to find the container associated to that process PID using vzpid it gives "0" CTID in the output. In older versions, it used to provide accurate CTID but not now. Here is the output of vzpid :


root@vnode:~# vzpid 19662
Pid CTID Name
19662 0 bundle

Is there any changes in newer versions ? Also i can see pct is recommend instead of vz commands now.

not recommended - the openvz commands simply don't work with LXC containers and vice versa.

an easy way to find out in which LXC container a process runs is by looking at the contents of /proc/PID/cgroup
 
  • Like
Reactions: shahzaib

t.lamprecht

Proxmox Staff Member
Staff member
Jul 28, 2015
5,331
1,641
164
South Tyrol/Italy
shop.proxmox.com
Edit: did not saw fabians reply, had the response already written but forgot to send :)

Hi,
yes a lot changed from PVE 3.x to PVE 4.x. The in its old form discontinued OpenVZ project was replaced with LXC (LinuX Container), so the old tools from openvz (vzctl, vzpid, but NOT vzdump) are not able to interact with LXC. So using our container tool (pct) is recommended.

pct has currently no support for mapping PID to VMID, but under linux such information is easily available through the /proc filesystem.
You could get the info with:
Code:
grep -oP "(?<=pids:/lxc/)\d+" "/proc/PID/cgroup"

just replace PID with the respective integer.

Or as a more advanced shell script with error checks and which accepts the PID as parameter:

Code:
#!/bin/sh

if [ ! -e "/proc/$1/cgroup" ]; then
   echo "no process with PID '$1' found!"
   exit 1
fi

grep -oP "(?<=pids:/lxc/)\d+" "/proc/$1/cgroup" || (echo "process with PID '$1' does not belong to an PVE CT"; exit 1)
(link to gist)

Save this on the node, I named it pid_to_vmid, make it executable with
Code:
chmod +x pid_to_vmid

Now you can call it with
Code:
./pid_to_vmid 12345
 
  • Like
Reactions: SamTzu

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!