lib/hawatel_ps/linux/proc_fetch.rb
def process_limits(pid)
          limits_file = "/proc/#{pid}/limits"
          limits_list = Array.new
          if File.readable?(limits_file)
            File.foreach(limits_file).each do |line|
              next if (line =~ /Limit/)
              line_split = line.split(' ')
              if line.split(' ')[1] == 'processes'
                lname = "#{line_split[1]}"
                lsoft = "#{line_split[2]} #{line_split[4]}"
                lhard = "#{line_split[3]} #{line_split[4]}"
              else
                lname = "#{line_split[1]}_#{line_split[2]}"
                if line.split(' ')[5]
                  lsoft = "#{line_split[3]} #{line_split[5]}"
                  lhard = "#{line_split[4]} #{line_split[5]}"
                else
                  lsoft = "#{line_split[3]}"
                  lhard = "#{line_split[4]}"
                end
              end
              limits_attrs = { :name => "#{lname}", :soft => "#{lsoft}", :hard => "#{lhard}" }
              limits_list << limits_attrs
            end
          else
            limits_list = ['Permission denied']
          end
          limits_list
        end
# Get soft and hard limits for process from limits file
#
# @example
#  p = process_limits('312')
#
#  p.limits.each do |limit|
#    puts "#{limit[name]} #{limit[:soft]} #{limit[:hard]}"
#  end
#
# @param pid [Fixnum] process pid
# @return [Array<Hash>]
Get soft and hard limits for process from limits file
Get soft and hard limits for process from limits file
def process_limits(pid)
          limits_file = "/proc/#{pid}/limits"
          limits_list = Array.new
          if File.readable?(limits_file)
            File.foreach(limits_file).each do |line|
              next if (line =~ /Limit/)
              line_split = line.split(' ')
              if line.split(' ')[1] == 'processes'
                lname = "#{line_split[1]}"
                lsoft = "#{line_split[2]} #{line_split[4]}"
                lhard = "#{line_split[3]} #{line_split[4]}"
              else
                lname = "#{line_split[1]}_#{line_split[2]}"
                if line.split(' ')[5]
                  lsoft = "#{line_split[3]} #{line_split[5]}"
                  lhard = "#{line_split[4]} #{line_split[5]}"
                else
                  lsoft = "#{line_split[3]}"
                  lhard = "#{line_split[4]}"
                end
              end
              limits_attrs = { :name => "#{lname}", :soft => "#{lsoft}", :hard => "#{lhard}" }
              limits_list << limits_attrs
            end
          else
            limits_list = ['Permission denied']
          end
          limits_list
        end
def process_limits ( pid ) limits_file = "/proc/#{pid}/limits" limits_list = Array . new if File . readable? ( limits_file ) File . foreach ( limits_file ) . each do | line | next if ( line =~ / Limit / ) line_split = line . split ( ' ' ) if line . split ( ' ' ) [ 1 ] == 'processes' lname = "#{line_split[1]}" lsoft = "#{line_split[2]} #{line_split[4]}" lhard = "#{line_split[3]} #{line_split[4]}" else lname = "#{line_split[1]}_#{line_split[2]}" if line . split ( ' ' ) [ 5 ] lsoft = "#{line_split[3]} #{line_split[5]}" lhard = "#{line_split[4]} #{line_split[5]}" else lsoft = "#{line_split[3]}" lhard = "#{line_split[4]}" end end limits_attrs = { :name => "#{lname}" , :soft => "#{lsoft}" , :hard => "#{lhard}" } limits_list << limits_attrs end else limits_list = [ 'Permission denied' ] end limits_list end
Get soft and hard limits for process from limits file
Get soft and hard limits for process from limits file
None
Array<Hash>
pid
None
example
p = process_limits('312') p.limits.each do |limit| puts "#{limit[name]} #{limit[:soft]} #{limit[:hard]}" end
p = process_limits ( ' 312 ' ) p . limits . each do |limit| puts " # { limit [ name ] } # { limit [ : soft ] } # { limit [ : hard ] } " end