Module: TrickBag::System

Defined in:
lib/trick_bag/system.rb

Overview

Convenience methods for dealing with Posix-compliant systems.

Class Method Summary collapse

Class Method Details

.command_available?(command) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/trick_bag/system.rb', line 21

def command_available?(command)
  raise "Cannot be called on a non-Posix operating system." unless OS.posix?
  system("which #{command} > /dev/null")
end

.lsof(options = '') ⇒ Object

Calls lsof to return information about all files *open by this process*. Output returned is lsof’s output, but after calling split(“n”) to create an array of the result strings.

Parameters:

  • options (defaults to: '')

    additional options to the lsof command line, if any, defaults to ”



14
15
16
17
18
# File 'lib/trick_bag/system.rb', line 14

def lsof(options = '')
  raise "Cannot be called on a non-Posix operating system." unless OS.posix?
  raise "lsof command not found" unless command_available?('lsof')
  `lsof #{options} -p #{Process.pid}`.split("\n")
end