I need to check if a process is running 
Author Message
 I need to check if a process is running

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



Sat, 06 Aug 2005 23:30:19 GMT  
 I need to check if a process is running

Quote:

> 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

Quote:
}

# 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*")



Sat, 06 Aug 2005 23:55:59 GMT  
 I need to check if a process is running

g> Is there any other method for this?
g> Is there any possibility to check this directly with ruby?

 Well, you can try to send the signal 0, ruby will raise the errors
 Errno::ESRCH  (process don't exist), Errno::EPERM (you don't have
 permission) otherwise the process is present

Guy Decoux



Sat, 06 Aug 2005 23:56:55 GMT  
 I need to check if a process is running
Hi,

At Wed, 19 Feb 2003 00:48:29 +0900,

Quote:

> I need to check if a process is running.

If that process is a child,

  unless Process.waitpid(pid, Process::WNOHANG)
    puts "#{pid} is running"
  end

or,

  begin
    Process.kill(0, pid)
    puts "#{pid} is running"
  rescue Errno::ESRCH
    puts "#{pid} is dead"
  end

--
Nobu Nakada



Sun, 07 Aug 2005 00:01:32 GMT  
 I need to check if a process is running

Quote:

> I need to check if a process is running.

On Linux:

pid = 2212
if FileTest.exist?("/proc/#{pid}")
  puts "process #{pid} is running"
end

Dan's sys-proctable is a more portable version.

Regards,

Tom



Sun, 07 Aug 2005 03:33:57 GMT  
 I need to check if a process is running

Quote:

> 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?

Process.kill(0, pid):

(kill with a signal of 0 sees if the process is still alive)

irb(main):001:0> Process.kill(0,$$)
1
irb(main):002:0> Process.kill(0,$$+1)
Errno::ESRCH: No such process
        from (irb):2:in `kill'
        from (irb):2
irb(main):003:0> exit

Quote:

> Thanks,
> Gian Paolo

        Hugh


Sun, 07 Aug 2005 23:06:22 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Need to know if Process is running

2. Need tcl help running process in Background.

3. Checking AM or PM

4. I am stuk CHECK my Code - access.txt (0/1)

5. backslash processing, am I on crack here?

6. Am I running under APL2 or TryAPL2?

7. I am running a vi that crashes after a period of time with no error message

8. How do i make my VIs run without the need to click the run button

9. Which Lisp am I running?

10. VW checking on a process

11. Checking termination of Process?

12. checking processes on servers

 

 
Powered by phpBB® Forum Software