summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzy <[email protected]>2023-12-05 00:48:55 -0500
committerzy <[email protected]>2023-12-05 00:48:55 -0500
commitd08269a9e274b986846c004e344b20fd916d7f73 (patch)
treec0cf9baab95780eb223fa12ce3ab8b179ef75d11
parent6accd46ac7f3163fc069fe3943035198702ec3a8 (diff)
print docker pid
-rwxr-xr-xget_pid.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/get_pid.sh b/get_pid.sh
new file mode 100755
index 0000000..923ea0c
--- /dev/null
+++ b/get_pid.sh
@@ -0,0 +1,31 @@
+
+#!/bin/bash
+
+# 获取所有正在运行的容器的 ID
+container_ids=$(docker ps -q)
+
+# 遍历容器 ID
+for id in $container_ids
+do
+ # 获取容器的名称
+ name=$(docker inspect --format '{{.Name}}' $id)
+ # 获取容器中所有进程在宿主机上的 PID
+ pids=$(docker top $id -eo pid)
+
+ # 打印容器的名称和 PID
+ echo "Container Name: $name, PIDs: $pids"
+done
+
+# # 遍历容器 ID
+# for id in $container_ids
+# do
+# # 获取容器的名称
+# name=$(docker inspect --format '{{.Name}}' $id)
+# # 获取容器的 PID
+# pid=$(docker inspect --format '{{.State.Pid}}' $id)
+# # 获取容器的 GID
+# gid=$(ps -o '%g' -p $pid | tail -1)
+
+# # 打印容器的名称、PID 和 GID
+# echo "Container Name: $name, PID: $pid, GID: $gid"
+# done \ No newline at end of file