Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting process status

70 views
Skip to first unread message

Joe Van Dyk

unread,
Mar 29, 2005, 8:51:59 PM3/29/05
to
If I have the id of a process, how can I get a Process::Status object for it?

Thanks,
Joe


Joe Van Dyk

unread,
Mar 29, 2005, 9:15:20 PM3/29/05
to

Actually, what I'm trying to do is create an application that will be
able to start, kill, and monitor programs on a bunch of linux
machines.

My initial attempt is using DRb.

I have a Node class that will run on each "node". The Node class will
have methods for starting, killing, and monitoring processes. I have
a NodeProcess object that enscapulates starting, killing, and
returning the status of a process.

I also have a NodeMonitor class that will connect to all the different
Node classes and let the user start/kill different processes on the
Node.

Does my design look ok? I'm having some difficulties correctly
starting a process and getting the status of a currently running or
killed process.

To start a process, I have something like
def start_process
@process_id = fork do
$logger.info "Executing '#{@command} #{@arguments}'"
Kernel.exec "#{@command} #{@arguments}"
end
$logger.info "New process id: #{@process_id}"
end
end
where @command and @arguments are just strings that have been set
already. But I'm getting the process id back of the "sh -c
some_command args" process, not the real process.

And I'm still struggling on how to get the status of my process.

Thanks for your input!

Joe


ES

unread,
Mar 29, 2005, 11:31:41 PM3/29/05
to
Joe Van Dyk wrote:
> If I have the id of a process, how can I get a Process::Status object for it?

Calling Process#wait should set $? which is the Status object
for the given pid.

> Thanks,
> Joe

E

--
No-one expects the Solaris POSIX implementation!

Joe Van Dyk

unread,
Mar 30, 2005, 12:15:12 AM3/30/05
to
On Wed, 30 Mar 2005 13:31:41 +0900, ES <rub...@magical-cat.org> wrote:
> Joe Van Dyk wrote:
> > If I have the id of a process, how can I get a Process::Status object for it?
>
> Calling Process#wait should set $? which is the Status object
> for the given pid.
>

That's not quite what I asked for. I have the pid of a specific
process and I need to find out its status (whether or not it's running
or not).


leon breedt

unread,
Mar 30, 2005, 1:13:19 AM3/30/05
to
On Wed, 30 Mar 2005 14:15:12 +0900, Joe Van Dyk <joev...@gmail.com> wrote:
> That's not quite what I asked for. I have the pid of a specific
> process and I need to find out its status (whether or not it's running
> or not).
On Linux at least, you can send signal 0 to determine whether a
process is running or not.

Process#kill(0, 2323)

Over here, I get an Errno::ESRCH exception raised if the process is not running.

Leon


Berger, Daniel

unread,
Mar 30, 2005, 9:42:36 AM3/30/05
to
> -----Original Message-----
> From: leon breedt [mailto:bit...@gmail.com]
> Sent: Tuesday, March 29, 2005 11:13 PM
> To: ruby-talk ML
> Subject: Re: Getting process status
>
>
> On Wed, 30 Mar 2005 14:15:12 +0900, Joe Van Dyk
> <joev...@gmail.com> wrote:
> > That's not quite what I asked for. I have the pid of a specific
> > process and I need to find out its status (whether or not
> it's running
> > or not).
> On Linux at least, you can send signal 0 to determine whether
> a process is running or not.

It works on all platforms, including Windows (with Ruby 1.8.x).

Regards,

Dan

0 new messages