Class: ChildProcess::AbstractProcess

### Home Classes Methods

### In Files

- lib/childprocess/abstract_process.rb

### Parent

Object

### Methods

- ::new
- #alive?
- #crashed?
- #exited?
- #io
- #pid
- #poll_for_exit
- #start
- #stop
- #wait

### Class/Module Index

Quicksearch

- ChildProcess
- ChildProcess::AbstractIO
- ChildProcess::AbstractProcess
- ChildProcess::Error
- ChildProcess::InvalidEnvironmentVariable
- ChildProcess::JRuby
- ChildProcess::JRuby::IO
- ChildProcess::JRuby::Process
- ChildProcess::JRuby::Pump
- ChildProcess::LaunchError
- ChildProcess::MissingPlatformError
- ChildProcess::SubclassResponsibility
- ChildProcess::TimeoutError
- ChildProcess::Tools
- ChildProcess::Tools::Generator
- ChildProcess::Unix
- ChildProcess::Unix::ForkExecProcess
- ChildProcess::Unix::IO
- ChildProcess::Unix::Lib
- ChildProcess::Unix::Lib::Attrs
- ChildProcess::Unix::Lib::FileActions
- ChildProcess::Unix::Platform
- ChildProcess::Unix::PosixSpawnProcess
- ChildProcess::Unix::PosixSpawnProcess::Argv
- ChildProcess::Unix::PosixSpawnProcess::Envp
- ChildProcess::Unix::Process
- ChildProcess::Windows
- ChildProcess::Windows::Handle
- ChildProcess::Windows::IO
- ChildProcess::Windows::IoCounters
- ChildProcess::Windows::JobObjectBasicLimitInformation
- ChildProcess::Windows::JobObjectExtendedLimitInformation
- ChildProcess::Windows::Lib
- ChildProcess::Windows::Process
- ChildProcess::Windows::Process::Job
- ChildProcess::Windows::ProcessBuilder
- ChildProcess::Windows::ProcessInfo
- ChildProcess::Windows::SecurityAttributes
- ChildProcess::Windows::StartupInfo
- Java
- Java::JavaIo
- Java::JavaIo::FileDescriptor
- Java::SunNioCh
- Java::SunNioCh::FileChannelImpl
- FFI
- FFI::MemoryPointer

No matching classes.

# ChildProcess::AbstractProcess

### Constants

POLL_INTERVAL

### Attributes

cwd[RW]

Set the child's current working directory.

detach[RW]

Set this to true if you do not care about when or if the process quits.

duplex[RW]

Set this to true if you want to write to the process' stdin (process.io.stdin)

environment[R]

Modify the child's environment variables

exit_code[R]
leader[RW]

Set this to true to make the child process the leader of a new process group

This can be used to make sure that all grandchildren are killed when the child process dies.

### Public Class Methods

new(args) click to toggle source

Create a new process with the given args.

@api private @see ChildProcess.build

    # File lib/childprocess/abstract_process.rb, line 43
    def initialize(args)
      unless args.all? { |e| e.kind_of?(String) }
        raise ArgumentError, "all arguments must be String: #{args.inspect}"
      end

      @args        = args
      @started     = false
      @exit_code   = nil
      @io          = nil
      @cwd         = nil
      @detach      = false
      @duplex      = false
      @leader      = false
      @environment = {}
    end

### Public Instance Methods

alive?() click to toggle source

Is this process running?

@return [Boolean]

    # File lib/childprocess/abstract_process.rb, line 124
    def alive?
      started? && !exited?
    end

crashed?() click to toggle source

Returns true if the process has exited and the exit code was not 0.

@return [Boolean]

    # File lib/childprocess/abstract_process.rb, line 134
    def crashed?
      exited? && @exit_code != 0
    end

exited?() click to toggle source

Did the process exit?

@return [Boolean]

    # File lib/childprocess/abstract_process.rb, line 114
    def exited?
      raise SubclassResponsibility, "exited?"
    end

io() click to toggle source

Returns a ChildProcess::AbstractIO subclass to configure the child's IO streams.

    # File lib/childprocess/abstract_process.rb, line 63
    def io
      raise SubclassResponsibility, "io"
    end

pid() click to toggle source

@return [Fixnum] the pid of the process after it has started

    # File lib/childprocess/abstract_process.rb, line 71
    def pid
      raise SubclassResponsibility, "pid"
    end

poll_for_exit(timeout) click to toggle source

Wait for the process to exit, raising a ChildProcess::TimeoutError if the timeout expires.

    # File lib/childprocess/abstract_process.rb, line 143
    def poll_for_exit(timeout)
      log "polling #{timeout} seconds for exit"

      end_time = Time.now + timeout
      until (ok = exited?) || Time.now > end_time
        sleep POLL_INTERVAL
      end

      unless ok
        raise TimeoutError, "process still alive after #{timeout} seconds"
      end
    end

start() click to toggle source

Launch the child process

@return [AbstractProcess] self

    # File lib/childprocess/abstract_process.rb, line 81
    def start
      launch_process
      @started = true

      self
    end

stop(timeout = 3) click to toggle source

Forcibly terminate the process, using increasingly harsher methods if possible.

@param [Fixnum] timeout (3) Seconds to wait before trying the next method.

    # File lib/childprocess/abstract_process.rb, line 94
    def stop(timeout = 3)
      raise SubclassResponsibility, "stop"
    end

wait() click to toggle source

Block until the process has been terminated.

@return [Fixnum] The exit status of the process

    # File lib/childprocess/abstract_process.rb, line 104
    def wait
      raise SubclassResponsibility, "wait"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.