Class BackgroundProcess
In: lib/background_process/background_process.rb
Parent: Object

Methods

detect   exitstatus   interrupt   kill   new   run   running?   sanitize_params   select_streams   wait  

Classes and Modules

Module BackgroundProcess::IOHelpers

Attributes

pid  [R] 
stderr  [R] 
stdin  [R] 
stdout  [R] 

Public Class methods

Initialize a BackgroundProcess task. Don‘t do this. Use BackgroundProcess.run or BackgroundProcess.run_pty instead

Run a command, connecting it‘s IO streams (stdin, sterr, stdout) via IO pipes, which are not tty IO streams.

Because of this, some programs (like ruby) will buffer their output and only make it available when it‘s explicitely flushed (with IO#flush or when the buffer gets full). This behavior can be overridden by setting the streams to sync, like this:

STDOUT.sync, STDERR.sync = true, true

If you can‘t control the program and have it explicitly flush its output when it should, or you can‘t tell the streams to run in sync mode, see PTYBackgroundProcess.run for a workaround.

Protected Class methods

It‘s protected. What do you care? :P

Public Instance methods

Calls block each time a line is available in the specified output buffer(s) and returns the first non-false value By default, both stdout and stderr are monitored.

Args:

  • which: which streams to monitor. valid values are :stdout, :stderr, or :both.
  • timeout: Total time in seconds to run detect for. If result not found within this time, abort and return nil. Pass nil for no timeout.
  • &block: the block to call. If block takes two arguments, it will pass both the stream that received the input (an instance of IO, not the symbol), and the line read from the buffer.

Waits for the process to terminate, and then returns the exit status

Sends the interrupt signal to the process. The equivalent of pressing control-C in it.

send a signal to the process. If the processes and running, do nothing. Valid signals are those in Signal.list. Default is "TERM"

asks the operating system is the process still exists.

waits for the process to finish. Freeze the process so it can rest in peace. You should call this on every background job you create to avoid a flood of zombie processes. (Processes won‘t go away until they are waited on)

Protected Instance methods

[Validate]