{"id":508,"date":"2024-04-02T12:06:21","date_gmt":"2024-04-02T10:06:21","guid":{"rendered":"https:\/\/kszyh.kisim.eu.org\/?p=508"},"modified":"2024-04-02T12:07:01","modified_gmt":"2024-04-02T10:07:01","slug":"in-which-container-pid-is-running","status":"publish","type":"post","link":"https:\/\/kszyh.kisim.eu.org\/?p=508","title":{"rendered":"In which container PID is running?"},"content":{"rendered":"<p>Sometimes we only know the PID (e.g. from nvidia-smi). We do not know what container the PID is running in.<\/p>\n<pre class=\"lang:sh decode:true \" >TARGET_PID=331711\r\nfor container in $(docker ps -q); do\r\n    if docker top $container | awk '{print $2}' | grep -q $TARGET_PID; then\r\n        container_name=$(docker inspect --format '{{.Name}}' $container | sed 's\/^\\\/\\(.*\\)\/\\1\/')\r\n        echo \"PID $TARGET_PID is running in container: $container (Name: $container_name)\"\r\n        exit 0\r\n    fi\r\ndone\r\necho \"PID $TARGET_PID is not running in any active container.\"\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we only know the PID (e.g. from nvidia-smi). We do not know what container the PID is running in. TARGET_PID=331711 for container in $(docker ps -q); do if docker top $container | awk '{print $2}&#8217; | grep -q $TARGET_PID; then container_name=$(docker inspect &#8211;format '{{.Name}}&#8217; $container | sed 's\/^\\\/\\(.*\\)\/\\1\/&#8217;) echo&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/kszyh.kisim.eu.org\/?p=508\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,23,19],"tags":[],"class_list":["post-508","post","type-post","status-publish","format-standard","hentry","category-bez-kategorii","category-linux","category-skrypty"],"_links":{"self":[{"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=508"}],"version-history":[{"count":2,"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/508\/revisions"}],"predecessor-version":[{"id":510,"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/508\/revisions\/510"}],"wp:attachment":[{"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kszyh.kisim.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}