<p>Using <code>crictl an </code>containerd<code>, is there an easy way to find to which pod/container belongs a given process, using it's </code>PID` on the host machine?</p>
<p>For example, how can I retrieve the name of the pod which runs the process below (<code>1747</code>):</p>
<pre><code>root@k8s-worker-node:/# ps -ef | grep mysql
1000        1747    1723  0 08:58 ?        00:00:01 mysqld
</code></pre>

Fabrice Jammes
<p>Assuming that you're looking at the primary process in a pod, you could do something like this:</p>
<pre><code>crictl ps -q | while read cid; do
    if crictl inspect -o go-template --template '{{ .info.pid }}' $cid | grep -q $target_pid; then
        echo $cid
    fi
done
</code></pre>
<p>This walks through all the crictl managed pods and checks the pod pid against the value of the <code>$target_pid</code> value (which you have set beforehand to the host pid in which you are interested).</p>
