Issue #12573 has been updated by William Johnston.


Pull request: https://github.com/ruby/ruby/pull/1399

----------------------------------------
Feature #12573: Introduce a straightforward way to discover whether a process is running
https://bugs.ruby-lang.org/issues/12573#change-59546

* Author: William Johnston
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
## Background

The best present solution is to kill the process with a signal of 0, and then evaluate the exit code and two possible exceptions to determine whether or not this process is alive. This is surprising when Ruby has so many beautiful ways of handling related things.

In Ruby, this looks like (from the process_exists gem):

```ruby
def self.exists?(pid)
  Process.kill(0, pid.to_i)
  true
rescue Errno::ESRCH # No such process
  false
rescue Errno::EPERM # The process exists, but you don't have permission to send the signal to it.
  true
end
```

## Usecase

I have a background process which needs to be able to determine whether or not another copy of it is running. This is accomplished via a PID file, but I need to be able to confirm whether the given PID actually exists.

## See also

Someone has already wrapped up a Ruby version of this into a gem (from which the Ruby implementation comes): https://github.com/wilsonsilva/process_exists




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>