Browse Source

Add Linux namespace commands

master
Pekka Helenius 3 years ago
parent
commit
2e8e08c631
2 changed files with 46 additions and 0 deletions
  1. +22
    -0
      tools/killns.sh
  2. +24
    -0
      tools/psns.sh

+ 22
- 0
tools/killns.sh View File

@ -0,0 +1,22 @@
#!/bin/env sh
if [[ ${1} =~ ^(\-h|\-\-help)$ ]] || [[ -z ${1} ]]; then
echo "
Send a signal to a process in specified namespace.
usage: $(basename $0) <signal> <processname> <namespace>
"
exit 0
fi
signal="${1}"
processname="${2}"
namespace="${3}"
for pid in $(sudo ip netns pids ${namespace}); do
if [[ $(sudo ps -q $pid -o command) =~ ^.*${processname}.* ]]; then
sudo ip netns exec ${namespace} kill -${signal} ${pid}
fi
done

+ 24
- 0
tools/psns.sh View File

@ -0,0 +1,24 @@
#!/bin/env sh
NAMESPACES=( $(ls /run/netns) )
if [[ ${1} =~ ^(\-h|\-\-help)$ ]]; then
echo "
List processes in non-default namespaces.
"
exit 0
fi
printf "%-25s%-20s%-20s%s%-15s%-30s%s\n" "USER" "PID" "COMMAND" "NAMESPACE"
echo "--------------------------------------------------------------------------"
for namespace in ${NAMESPACES[@]}; do
for pid in $(sudo ip netns pids ${namespace}); do
printf "%-25s%-20s%-20s%s%-15s%-30s%s\n" $(ps -q ${pid} -o uname,pid,comm= | tail -1) ${namespace}
done
done
echo "To alter a process, use: $(killns)"

Loading…
Cancel
Save