-
Notifications
You must be signed in to change notification settings - Fork 2
/
lxc-pid
executable file
·36 lines (34 loc) · 946 Bytes
/
lxc-pid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/lxc-pid
#
# show the full process including virtual hostname for a PID or PNAME
if [ -z "$1" ]
then
echo "lxc-pid: show the full process including virtual hostname for a PID or PNAME"
echo "error: $0 [process_name|pid]"
exit 1
fi
if [ -z "${1//[0-9]/}" ];
then
PID=$1
else
PNAME=$1
fi
if [ -n "${PID}" ];
then
for HOST in $(find /sys/fs/cgroup/memory/lxc -iname cgroup.procs -exec grep -il ${PID} {} \; | cut -d/ -f7)
do
echo "${HOST} $(ps --no-headers --pid=${PID})"
done
else
for PID in $(pgrep "${PNAME}")
do
for HOST in $(find /sys/fs/cgroup/memory/lxc -iname cgroup.procs -exec grep -il ${PID} {} \; | cut -d/ -f7)
do
echo "${HOST} $(ps --no-headers --pid=${PID})"
done
done
fi