Process

class Process

Defined in:

kernel.cr
process.cr
process/executable_path.cr
process/executable_path.cr

Constant Summary

PATH_DELIMITER = {% if flag?(:windows) %} ';' {% else %} ':' {% end %}

Class Method Summary

Instance Method Summary

Class Method Detail

def self.after_fork_child_callbacksSource

Hooks are defined here due to load order problems.

def self.exec(command : String, args = nil, env : Env = nil, clear_env : Bool = false, shell : Bool = false, input : Bool | IO::FileDescriptor = true, output : Bool | IO::FileDescriptor = true, error : Bool | IO::FileDescriptor = true, chdir : String? = nil)Source

Replaces the current process with a new one.

The possible values for input, output and error are:

  • false: no IO (-dev-null)
  • true: inherit from parent
  • IO: use the given IO

def self.executable_pathSource

Returns an absolute path to the executable file of the currently running program. This is in opposition to PROGRAM_NAME which may be a relative or absolute path, just the executable file name or a symlink.

The executable path will be canonicalized (all symlinks and relative paths will be expanded).

Returns nil if the file can't be found.

def self.exists?(pid : Int)Source

Returns true if the process identified by pid is valid for a currently registered process, false otherwise. Note that this returns true for a process in the zombie or similar state.

def self.exit(status = 0)Source

Terminate the current process immediately. All open files, pipes and sockets are flushed and closed, all child processes are inherited by PID 1. This does not run any handlers registered with at_exit, use ::exit for that.

status is the exit status of the current process.

def self.find_executable(name, path = ENV["PATH"]?, pwd = Dir.current)Source

Searches an executable, checking for an absolute path, a path relative to pwd or absolute path, then eventually searching in directories declared in path.

def self.fork(&block)Source

Runs the given block inside a new process and returns a Process representing the new child process.

def self.fork : self?Source

Duplicates the current process. Returns a Process representing the new child process in the current process and nil inside the new child process.

def self.kill(signal : Signal, *pids : Int)Source

Sends a signal to the processes identified by the given pids.

def self.new(command : String, args = nil, env : Env = nil, clear_env : Bool = false, shell : Bool = false, input : Stdio = false, output : Stdio = false, error : Stdio = false, chdir : String? = nil)Source

Creates a process, executes it, but doesn't wait for it to complete.

To wait for it to finish, invoke #wait.

By default the process is configured without input, output or error.

def self.pgid : LibC::PidTSource

Returns the process group identifier of the current process.

def self.pgid(pid : Int32) : LibC::PidTSource

Returns the process group identifier of the process identified by pid.

def self.pid : LibC::PidTSource

Returns the process identifier of the current process.

def self.ppid : LibC::PidTSource

Returns the process identifier of the parent process of the current process.

def self.run(command : String, args = nil, env : Env = nil, clear_env : Bool = false, shell : Bool = false, input : Stdio = false, output : Stdio = false, error : Stdio = false, chdir : String? = nil) : Process::StatusSource

Executes a process and waits for it to complete.

By default the process is configured without input, output or error.

def self.run(command : String, args = nil, env : Env = nil, clear_env : Bool = false, shell : Bool = false, input : Stdio = nil, output : Stdio = nil, error : Stdio = nil, chdir : String? = nil, &block)Source

Executes a process, yields the block, and then waits for it to finish.

By default the process is configured to use pipes for input, output and error. These will be closed automatically at the end of the block.

Returns the block's value.

def self.times : TmsSource

Returns a Tms for the current process. For the children times, only those of terminated children are returned.

Instance Method Detail

def closeSource

Closes any pipes to the child process.

def errorSource

A pipe to this process's error. Raises if a pipe wasn't asked when creating the process.

def error? : IO::FileDescriptor?Source

A pipe to this process's error. Raises if a pipe wasn't asked when creating the process.

def exists?Source

Whether the process is still registered in the system. Note that this returns true for processes in the zombie or similar state.

def inputSource

A pipe to this process's input. Raises if a pipe wasn't asked when creating the process.

def input? : IO::FileDescriptor?Source

A pipe to this process's input. Raises if a pipe wasn't asked when creating the process.

def kill(sig = Signal::TERM)Source

See also: Process.kill

def outputSource

A pipe to this process's output. Raises if a pipe wasn't asked when creating the process.

def output? : IO::FileDescriptor?Source

A pipe to this process's output. Raises if a pipe wasn't asked when creating the process.

def pid : Int32Source

def terminated?Source

Whether this process is already terminated.

def wait : Process::StatusSource

Waits for this process to complete and closes any pipes.

© 2012–2017 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.22.0/Process.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部