class Object

Public Instance Methods

find_process(*pattern) click to toggle source
# File lib/ps_grep.rb, line 15
def find_process(*pattern)
    mongrels = []
    
    s = pattern.join(" | grep ")

    command = "ps aux | grep -v grep | grep #{s}"
    p "command=>#{command}"
    r = `#{command}`
    print "==>command output<===\n#{r}"
    print "==>command output end<===\n"
    
    if $_OS_TYPE == "linux"
    
    
        r.scan(/^(.*?)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+)\s+(\d+)\s+(.*?)\s+(.*?)\s+(.*?)\s+(\d+:\d+\.\d+)\s+(.*?)$/){|m|
            mongrels.push({
                :user=>m[0].strip,
                :pid=>m[1],
                :cpu=>m[2],
                :mem1=>m[3],
                :mem2=>m[4],
                :mem3=>m[5],
                :start=>m[8],
                :time=>m[9],
                :cmd=>m[10].strip
            })
        }
    elsif $_OS_TYPE == "darwin"
        r.scan(/^(.*?)\s+(\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+)\s+(\d+)\s+(.*?)\s+(.*?)\s+(.*?)\s+(\d+:\d+\.\d+)\s+(.*?)$/){|m|
            mongrels.push({
                :user=>m[0].strip,
                :pid=>m[1],
                :cpu=>m[2],
                :mem1=>m[3],
                :mem2=>m[4],
                :mem3=>m[5],
                :start=>m[8],
                :time=>m[9],
                :cmd=>m[10].strip
            })
        }
    else
        p "OS #{$_OS_TYPE} is not supported"
    end 
    
    return mongrels
end