Sha256: 146c2a222ac3188daf8e4d5f1c06dc970c99bdd6648c4b4fc612d9921012af1e

Contents?: true

Size: 1.08 KB

Versions: 186

Compression:

Stored size: 1.08 KB

Contents

#!/usr/bin/env ruby

require 'rbbt-util'
require 'rbbt/util/simpleopt'
require 'rbbt/workflow'
require 'rbbt/monitor'

$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands

options = SOPT.setup <<EOF

Find process with deleted open files

$ rbbt system deleted_files 

-h--help Print this help
EOF
rbbt_usage and exit 0 if options[:help]

pids = {}
Dir.glob('/proc/*/fd/*').each do |file|
  pid = file.split('/')[-3]
  begin
    dest = File.readlink(file)
  rescue
    next
  end
  next if File.exists? dest
  pids[pid] ||= []
  pids[pid] << dest
end

pids.sort_by{|p,files| files.length}.each do |pid,files|
    dirs = {}
    files.each do |f|
        name = File.basename(f)
        dir = File.basename(File.dirname(f))
        next if dir =~ /^pts|\.$/
        dirs[dir] ||= []
        dirs[dir] << name
    end
    next if dirs.empty?
    puts Log.color :magenta, pid
    dirs.sort_by{|dir,list| list.length}.each do |dir,list|
        puts Misc.format_definition_list_item(dir, list.length.to_s)
    end
end

puts "Total: #{pids.values.collect{|k,v| v}.flatten.length}"

Version data entries

186 entries across 186 versions & 1 rubygems

Version Path
rbbt-util-5.20.9 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.8 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.7 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.6 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.5 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.4 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.3 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.2 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.1 share/rbbt_commands/system/deleted_files
rbbt-util-5.20.0 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.37 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.36 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.35 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.34 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.32 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.31 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.30 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.29 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.28 share/rbbt_commands/system/deleted_files
rbbt-util-5.19.27 share/rbbt_commands/system/deleted_files