def run(argv = [])
@options.parse!(argv)
pid_path = argv.delete_at(0)
dirname = Pathname.new('.').realpath.basename.to_s
pid_path = File.join(Dir.pwd, dirname + '.pid') if pid_path.nil?
if File.directory?(pid_path)
pid_path = File.join(pid_path, File.basename(pid_path) + '.pid')
end
pid_path = Pathname.new(pid_path).expand_path.to_s
if !File.exist?(pid_path)
abort "The PID #{pid_path} does not exist"
end
unless is_running?(pid_path)
abort "The Ramaze application for #{pid_path} isn't running"
end
pid = File.read(pid_path).to_i
if is_windows?
wmi = WIN32OLE.connect("winmgmts://")
ours = []
processes = wmi.ExecQuery(
"select * from win32_process where ProcessId = #{pid}"
)
processes.each do |p|
ours << [
p.Name,
p.CommandLine,
p.VirtualSize,
p.CreationDate,
p.ExecutablePath,
p.Status
]
end
puts Statistics % ours.first
else
if File.directory?(proc_dir = Pathname.new('/proc'))
proc_dir = proc_dir.join(pid.to_s)
if File.file?(stat_file = proc_dir.join("stat"))
stats = File.read(stat_file).split
puts Statistics % [
nil,
File.read(proc_dir.join("cmdline")).split("\000").join(" "),
"%s k" % (stats[22].to_f / 1024),
File.mtime(proc_dir),
File.readlink(proc_dir.join("exe")),
stats[2]
]
end
else
begin
puts %x{ps l #{pid}}
rescue
puts "Sadly no more information is available"
end
end
end
end