':' Creates a process, executes it, but doesn't wait for it to complete.
Changes the root directory and the current working directory for the current process.
Returns whether a debugger is attached to the current process.
EXPERIMENTAL
Replaces the current process with a new one.
Returns an absolute path to the executable file of the currently running program.
Returns true if the process identified by pid is valid for a currently registered process, false otherwise.
Terminate the current process immediately.
Searches an executable, checking for an absolute path, a path relative to pwd or absolute path, then eventually searching in directories declared in path.
Ignores all interrupt requests.
Installs handler as the new handler for interrupt requests.
DEPRECATED Use #on_terminate instead
Installs handler as the new handler for termination requests.
Splits the given line into individual command-line arguments in a platform-specific manner, unquoting tokens if necessary.
Splits the given line into individual command-line arguments according to POSIX shell rules, unquoting tokens if necessary.
Splits the given line into individual command-line arguments according to Microsoft's standard C runtime, unquoting tokens if necessary.
Returns the process group identifier of the process identified by pid.
Returns the process group identifier of the current process.
Returns the process identifier of the current process.
Returns the process identifier of the parent process of the current process.
Converts a sequence of strings to one joined string with each argument shell-quoted.
Shell-quotes one item, same as .quote({arg}).
Converts a sequence of strings to one joined string with each argument shell-quoted.
Shell-quotes one item, same as .quote_posix({arg}).
Restores default handling of interrupt requests.
Executes a process and waits for it to complete.
Executes a process, yields the block, and then waits for it to finish.
Sends signal to the process identified by pid.
Returns a Tms for the current process.
Closes any system resources (e.g.
A pipe to this process' error.
A pipe to this process' error.
Whether the process is still registered in the system.
A pipe to this process' input.
A pipe to this process' input.
A pipe to this process' output.
A pipe to this process' output.
Returns the process identifier of this process.
Sends signal to this process.
Asks this process to terminate.
Whether this process is already terminated.
Waits for this process to complete and closes any pipes.
Reference
Reference
Reference
Object
Object
Object
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.
If shell is false, the command is the path to the executable to run, along with a list of args.
If shell is true, the command should be the full command line including space-separated args.
/bin/sh to process the command string. args are also passed to the shell, and you need to include the string "${@}" in the command to safely insert them there.Raises IO::Error if executing the command fails (for example if the executable doesn't exist).
Changes the root directory and the current working directory for the current process.
Available only on Unix-like operating systems.
Security: .chroot on its own is not an effective means of mitigation. At minimum the process needs to also drop privileges as soon as feasible after the .chroot. Changes to the directory hierarchy or file descriptors passed via recvmsg(2) from outside the .chroot jail may allow a restricted process to escape, even if it is unprivileged.
Process.chroot("/var/empty") Returns whether a debugger is attached to the current process.
Currently supported on Windows and Linux. Always returns false on other systems.
EXPERIMENTAL
Replaces the current process with a new one. This function never returns.
Raises IO::Error if executing the command fails (for example if the executable doesn't exist).
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.
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.
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.
Searches an executable, checking for an absolute path, a path relative to pwd or absolute path, then eventually searching in directories declared in path.
Ignores all interrupt requests. Removes any custom interrupt handler set with #on_terminate.
Installs handler as the new handler for interrupt requests. Removes any previously set interrupt handler.
The handler is executed on a fresh fiber every time an interrupt occurs.
SIGINT.DEPRECATED Use #on_terminate instead
Installs handler as the new handler for termination requests. Removes any previously set termination handler.
The handler is executed on a fresh fiber every time an interrupt occurs.
SIGINT, SIGHUP and SIGTERM.wait_channel = Channel(Nil).new
Process.on_terminate do |reason|
case reason
when .interrupted?
puts "terminating gracefully"
wait_channel.close
when .terminal_disconnected?
puts "reloading configuration"
when .session_ended?
puts "terminating forcefully"
Process.exit
end
end
wait_channel.receive?
puts "bye" Splits the given line into individual command-line arguments in a platform-specific manner, unquoting tokens if necessary.
Equivalent to .parse_arguments_posix on Unix-like systems. Equivalent to .parse_arguments_windows on Windows.
Splits the given line into individual command-line arguments according to POSIX shell rules, unquoting tokens if necessary.
Raises ArgumentError if a quotation mark is unclosed.
Process.parse_arguments_posix(%q["foo bar" '\hello/' Fizz\ Buzz]) # => ["foo bar", "\\hello/", "Fizz Buzz"]
See https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_03
Splits the given line into individual command-line arguments according to Microsoft's standard C runtime, unquoting tokens if necessary.
Raises ArgumentError if a quotation mark is unclosed. Leading spaces in line are ignored. Otherwise, this method is equivalent to CommandLineToArgvW for some unspecified program name.
NOTE This does not take strings that are passed to the CMD shell or used in a batch script.
Process.parse_arguments_windows(%q[foo"bar \\\"hello\\" Fizz\Buzz]) # => ["foobar \\\"hello\\", "Fizz\\Buzz"]
Returns the process group identifier of the process identified by pid.
Returns the process identifier of the parent process of the current process.
On Windows, the parent is associated only at process creation time, and the system does not re-parent the current process if the parent terminates; thus Process.exists?(Process.ppid) is not guaranteed to be true.
Converts a sequence of strings to one joined string with each argument shell-quoted.
This is then safe to pass as part of the command when using shell: true or system().
NOTE The actual return value is system-dependent, so it mustn't be relied on in other contexts. See also: .quote_posix.
files = ["my file.txt", "another.txt"]
`grep -E 'fo+' -- #{Process.quote(files)}` Shell-quotes one item, same as .quote({arg}).
Converts a sequence of strings to one joined string with each argument shell-quoted.
This is then safe to pass to a POSIX shell.
files = ["my file.txt", "another.txt"] Process.quote_posix(files) # => "'my file.txt' another.txt"
Shell-quotes one item, same as .quote_posix({arg}).
Executes a process and waits for it to complete.
By default the process is configured without input, output or error.
Raises IO::Error if executing the command fails (for example if the executable doesn't exist).
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.
Raises IO::Error if executing the command fails (for example if the executable doesn't exist).
Sends signal to the process identified by pid.
Returns a Tms for the current process. For the children times, only those of terminated children are returned on Unix; they are zero on Windows.
A pipe to this process' error. Raises if a pipe wasn't asked when creating the process.
A pipe to this process' error. Raises if a pipe wasn't asked when creating the process.
Whether the process is still registered in the system. Note that this returns true for processes in the zombie or similar state.
A pipe to this process' input. Raises if a pipe wasn't asked when creating the process.
A pipe to this process' input. Raises if a pipe wasn't asked when creating the process.
A pipe to this process' output. Raises if a pipe wasn't asked when creating the process.
A pipe to this process' output. Raises if a pipe wasn't asked when creating the process.
Sends signal to this process.
NOTE #terminate is preferred over #signal(Signal::TERM) and #signal(Signal::KILL) as a portable alternative which also works on Windows.
Asks this process to terminate.
If graceful is true, prefers graceful termination over abrupt termination if supported by the system.
Signal::TERM to be sent to the process instead of Signal::KILL.Waits for this process to complete and closes any pipes.
© 2012–2026 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/1.19.0/Process.html