Skip to content

Instantly share code, notes, and snippets.

@ryan5500
Created January 19, 2012 02:39
Show Gist options
  • Save ryan5500/1637339 to your computer and use it in GitHub Desktop.
Save ryan5500/1637339 to your computer and use it in GitHub Desktop.
get ruby process pid using pty lib
#!/usr/bin/env ruby
# conding: utf-8
#
# this script shows pid which contains 'ruby'
#
require 'pty'
cmd = 'ps aux | grep ruby'
PTY.spawn(cmd) do |reader, writer, pid|
val = reader.readlines.collect {|line| line.chomp }
puts val.first.split(' ')[1]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment