Sha256: 4ce4f1cddb7f435774e9c5cb7fc219a45e642f8b9ad234f9c00a8559bad852aa

Contents?: true

Size: 1.25 KB

Versions: 12

Compression:

Stored size: 1.25 KB

Contents

module ChildProcess
  module Unix
    class Process < AbstractProcess
      attr_reader :pid

      def io
        @io ||= Unix::IO.new
      end

      def stop(timeout = 3)
        assert_started
        send_term

        begin
          return poll_for_exit(timeout)
        rescue TimeoutError
          # try next
        end

        send_kill
        wait
      rescue Errno::ECHILD, Errno::ESRCH
        # handle race condition where process dies between timeout
        # and send_kill
        true
      end

      def exited?
        return true if @exit_code

        assert_started
        pid, status = ::Process.waitpid2(@pid, ::Process::WNOHANG)

        log(:pid => pid, :status => status)

        if pid
          @exit_code = status.exitstatus || status.termsig
        end

        !!pid
      end

      def wait
        assert_started
        pid, status = ::Process.waitpid2 @pid

        @exit_code = status.exitstatus || status.termsig
      end

      private

      def send_term
        send_signal 'TERM'
      end

      def send_kill
        send_signal 'KILL'
      end

      def send_signal(sig)
        assert_started

        log "sending #{sig}"
        ::Process.kill sig, @pid
      end

    end # Process
  end # Unix
end # ChildProcess

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/process.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/process.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/process.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/process.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/process.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/process.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/childprocess-0.3.1/lib/childprocess/unix/process.rb
childprocess-0.3.1 lib/childprocess/unix/process.rb
childprocess-0.3.0 lib/childprocess/unix/process.rb
childprocess-0.2.9 lib/childprocess/unix/process.rb
childprocess-0.2.8 lib/childprocess/unix/process.rb
childprocess-0.2.7 lib/childprocess/unix/process.rb