From: Daniel Berger Date: 2003-02-19T00:55:59+09:00 Subject: Re: I need to check if a process is running gp wrote: > Hi, > > I need to check if a process is running. > I have this code for this: > > ------------------------------------------ > pid="2212" > cmd="ps -f p "+pid > out=`#{cmd}` > lines=out.split(/\n/) > if (lines.length==1) then > print "Process with PID="+pid+" doesn't running.\n" > end > if (lines.length==2) then > print "Process with PID="+pid+" is running.\n" > end > ------------------------------------------ > > Is there any other method for this? > Is there any possibility to check this directly with ruby? > > Thanks, > Gian Paolo require "sys/proctable" include Sys ProcTable.ps{ |p| if p.pid == 2212 puts "Process [" + p.pid.to_s + "] is running" end } # or if ProcTable.ps(2212).empty? puts "Process not running" end sys-proctable is available on the RAA. It currently supports Linux, Solaris and FreeBSD. Windows support on the way. Regards, Dan -- a = [74, 117, 115, 116, 32, 65, 110, 111, 116, 104, 101, 114, 32, 82] a.push(117,98, 121, 32, 72, 97, 99, 107, 101, 114) puts a.pack("C*")