Skip to content

Instantly share code, notes, and snippets.

@teddyking
Created October 4, 2016 08:28
Show Gist options
  • Select an option

  • Save teddyking/9fdffb3331ed1bc1bc40d104164a4122 to your computer and use it in GitHub Desktop.

Select an option

Save teddyking/9fdffb3331ed1bc1bc40d104164a4122 to your computer and use it in GitHub Desktop.
Hacktastic script to print a PID from each mount namespace on a host
mntnses = Dir.glob("/proc/*/ns/mnt")
foundmnts = []
foundpids = []
mntnses.each do |mntns|
actualmntns = `readlink "#{mntns}"`
pid = mntns.split("/")[2]
mntnum = actualmntns.gsub(/mnt:\[/, "").gsub(/\]/, "")
#puts "#{pid} - #{mntnum}"
if ! foundmnts.include? mntnum
foundmnts << mntnum
foundpids << pid
end
end
puts foundpids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment