check-namespaces.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Listing processes and their associated user namespaces:" | |
for pid in $(ls /proc | grep '^[0-9]*$'); do | |
if [ -e /proc/$pid/ns/user ]; then | |
# Get the process command line | |
cmdline=$(cat /proc/$pid/cmdline | tr '\0' ' ') | |
# Get the process owner | |
owner=$(ps -o user= -p $pid) | |
# Get the user namespace inode | |
namespace_inode=$(ls -l /proc/$pid/ns/user | awk '{print $11}') | |
# Get the process name | |
process_name=$(ps -p $pid -o comm=) | |
echo "PID: $pid" | |
echo "Process Name: $process_name" | |
echo "Command Line: $cmdline" | |
echo "Owner: $owner" | |
echo "Namespace Inode: $namespace_inode" | |
echo "----------------------------------------" | |
fi | |
done |