Skip to content

Instantly share code, notes, and snippets.

@picatz
Created November 6, 2016 06:21
Show Gist options
  • Save picatz/d2bdb8a13b5afafe96589c3765656a37 to your computer and use it in GitHub Desktop.
Save picatz/d2bdb8a13b5afafe96589c3765656a37 to your computer and use it in GitHub Desktop.
Using fosl to examine an pid
require 'fosl/parser'
pid = "27869"
parser = FOSL::Parser.new
data = parser.lsof("-p #{pid}")
# => example output ...
# data => {27869=>
# #<FOSL::Process:0x00000001c64480
# @command="ruby",
# @files=
# [{:fd=>"cwd", :type=>"DIR", :name=>"/home/vagrant"},
# {:fd=>"rtd", :type=>"DIR", :name=>"/"},
# {:fd=>"txt", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/digest/sha1.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/digest/md5.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/lib/x86_64-linux-gnu/libnss_files-2.19.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/io/wait.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/socket.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/json/ext/generator.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/enc/utf_32le.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/enc/utf_32be.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/enc/utf_16le.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/enc/utf_16be.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/json/ext/parser.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/io/nonblock.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/digest.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/lib/x86_64-linux-gnu/libssl.so.1.0.0"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/openssl.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/strscan.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/cgi/escape.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/date_core.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/etc.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/stringio.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/enc/trans/transdb.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-linux/enc/encdb.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/lib/x86_64-linux-gnu/libc-2.19.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/lib/x86_64-linux-gnu/libm-2.19.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/lib/x86_64-linux-gnu/libcrypt-2.19.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/lib/x86_64-linux-gnu/libdl-2.19.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/lib/x86_64-linux-gnu/libgmp.so.10.2.0"},
# {:fd=>"mem", :type=>"REG", :name=>"/lib/x86_64-linux-gnu/libpthread-2.19.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/local/rvm/rubies/ruby-2.3.0/lib/libruby.so.2.3.0"},
# {:fd=>"mem", :type=>"REG", :name=>"/lib/x86_64-linux-gnu/ld-2.19.so"},
# {:fd=>"mem", :type=>"REG", :name=>"/usr/lib/locale/locale-archive"},
# {:fd=>0, :type=>"CHR", :name=>"/dev/pts/3"},
# {:fd=>1, :type=>"CHR", :name=>"/dev/pts/3"},
# {:fd=>2, :type=>"CHR", :name=>"/dev/pts/3"},
# {:fd=>3, :type=>"FIFO", :name=>"pipe"},
# {:fd=>4, :type=>"FIFO", :name=>"pipe"},
# {:fd=>5, :type=>"FIFO", :name=>"pipe"},
# {:fd=>6, :type=>"FIFO", :name=>"pipe"},
# {:fd=>7, :type=>"IPv6", :protocol=>"TCP", :name=>"localhost:http", :state=>"LISTEN", :read_queue=>"0", :send_queue=>"0"},
# {:fd=>8, :type=>"IPv4", :protocol=>"TCP", :name=>"localhost:http", :state=>"LISTEN", :read_queue=>"0", :send_queue=>"0"},
# {:fd=>9, :type=>"FIFO", :name=>"pipe"},
# {:fd=>10, :type=>"FIFO", :name=>"pipe"}],
# @login="root",
# @pid=27869>}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment