Module Process
In: process.rb

Methods

create   fork   kill   wait   wait2   waitpid   waitpid2  

Included Modules

Windows::Process Windows::Error Windows::Library Windows::Console Windows::Handle Windows::Synchronize Windows::Window

Constants

WIN32_PROCESS_VERSION = '0.5.2'
ProcessInfo = Struct.new("ProcessInfo", :process_handle, :thread_handle, :process_id, :thread_id   Used by Process.create

Public Instance methods

Process.create(key => value, …) => ProcessInfo

This is a wrapper for the CreateProcess() function. It executes a process, returning a ProcessInfo struct. It accepts a hash as an argument. There are six primary keys:

  • app_name (mandatory)
  • inherit (default: false)
  • process_inherit (default: false)
  • thread_inherit (default: false)
  • creation_flags (default: 0)
  • cwd (default: Dir.pwd)
  • startup_info (default: nil)
  • environment (default: nil)

Of these, the ‘app_name’ must be specified or an error is raised.

The startup_info key takes a hash. Its keys are attributes that are part of the StartupInfo struct, and are generally only meaningful for GUI or console processes. See the documentation on CreateProcess() and the StartupInfo struct on MSDN for more information.

  • desktop
  • title
  • x
  • y
  • x_size
  • y_size
  • x_count_chars
  • y_count_chars
  • fill_attribute
  • sw_flags
  • startf_flags
  • stdin
  • stdout
  • stderr

The relevant constants for ‘creation_flags’, ‘sw_flags’ and ‘startf_flags’ are included in the Windows::Process, Windows::Console and Windows::Window modules. These come with the windows-pr package, a prerequisite of this package. Note that the ‘stdin’, ‘stdout’ and ‘stderr’ options can be either Ruby IO objects or file descriptors (i.e. a fileno). However, StringIO objects are not currently supported.

The ProcessInfo struct contains the following members:

  • process_handle - The handle to the newly created process.
  • thread_handle - The handle to the primary thread of the process.
  • process_id - Process ID.
  • thread_id - Thread ID.

Creates the equivalent of a subshell via the CreateProcess() function. This behaves in a manner that is similar, but not identical to, the Kernel.fork method for Unix.

Sends the given signal to an array of process id‘s. The signal may be any value from 0 to 9, or the special strings ‘SIGINT’ (or ‘INT’), ‘SIGBRK’ (or ‘BRK’) and ‘SIGKILL’ (or ‘KILL’). An array of successfully killed pids is returned.

Signal 0 merely tests if the process is running without killing it. Signal 2 sends a CTRL_C_EVENT to the process. Signal 3 sends a CTRL_BRK_EVENT to the process. Signal 9 kills the process in a harsh manner. Signals 1 and 4-8 kill the process in a nice manner.

SIGINT/INT corresponds to signal 2 SIGBRK/BRK corresponds to signal 3 SIGKILL/KILL corresponds to signal 9

Signals 2 and 3 only affect console processes, and then only if the process was created with the CREATE_NEW_PROCESS_GROUP flag.

Waits for any child process to exit and returns the process id of that child.

Note that the $? (Process::Status) global variable is NOT set. This may be addressed in a future release.

Waits for any child process to exit and returns an array containing the process id and the exit status of that child.

Note that the $? (Process::Status) global variable is NOT set. This may be addressed in a future release.

Waits for the given child process to exit and returns that pid.

Note that the $? (Process::Status) global variable is NOT set. This may be addressed in a future release.

Waits for the given child process to exit and returns an array containing the process id and the exit status.

Note that the $? (Process::Status) global variable is NOT set. This may be addressed in a future release.

[Validate]