Sha256: e462ce3094a0ca9ad7131616fbfad737f3f222bc3efc2790623b47eb98f59aef

Contents?: true

Size: 1.08 KB

Versions: 561

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.exist? 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

561 entries across 561 versions & 1 rubygems

Version Path
rbbt-util-5.44.1 share/rbbt_commands/system/deleted_files
rbbt-util-5.43.0 share/rbbt_commands/system/deleted_files
rbbt-util-5.42.0 share/rbbt_commands/system/deleted_files
rbbt-util-5.41.1 share/rbbt_commands/system/deleted_files
rbbt-util-5.41.0 share/rbbt_commands/system/deleted_files
rbbt-util-5.40.5 share/rbbt_commands/system/deleted_files
rbbt-util-5.40.4 share/rbbt_commands/system/deleted_files
rbbt-util-5.40.3 share/rbbt_commands/system/deleted_files
rbbt-util-5.40.0 share/rbbt_commands/system/deleted_files
rbbt-util-5.39.0 share/rbbt_commands/system/deleted_files
rbbt-util-5.38.1 share/rbbt_commands/system/deleted_files
rbbt-util-5.38.0 share/rbbt_commands/system/deleted_files
rbbt-util-5.37.16 share/rbbt_commands/system/deleted_files
rbbt-util-5.37.15 share/rbbt_commands/system/deleted_files
rbbt-util-5.37.14 share/rbbt_commands/system/deleted_files
rbbt-util-5.37.13 share/rbbt_commands/system/deleted_files
rbbt-util-5.37.12 share/rbbt_commands/system/deleted_files
rbbt-util-5.37.11 share/rbbt_commands/system/deleted_files
rbbt-util-5.37.10 share/rbbt_commands/system/deleted_files
rbbt-util-5.37.9 share/rbbt_commands/system/deleted_files