Ruby 3.4.5p51 (2025-07-16 revision 20cda200d3ce092571d0b5d342dadca69636cb0f)
|
Public APIs related to rb_mProcess. More...
#include "ruby/internal/attr/nonnull.h"
#include "ruby/internal/attr/noreturn.h"
#include "ruby/internal/config.h"
#include "ruby/internal/dllexport.h"
#include "ruby/internal/value.h"
Go to the source code of this file.
Functions | |
VALUE | rb_process_status_wait (rb_pid_t pid, int flags) |
Wait for the specified process to terminate, reap it, and return its status. | |
void | rb_last_status_set (int status, rb_pid_t pid) |
Sets the "last status", or the $?. | |
VALUE | rb_last_status_get (void) |
Queries the "last status", or the $?. | |
int | rb_proc_exec (const char *cmd) |
Executes a shell command. | |
VALUE | rb_f_exec (int argc, const VALUE *argv) |
Replaces the current process by running the given external command. | |
rb_pid_t | rb_waitpid (rb_pid_t pid, int *status, int flags) |
Waits for a process, with releasing GVL. | |
void | rb_syswait (rb_pid_t pid) |
This is a shorthand of rb_waitpid without status and flags. | |
rb_pid_t | rb_spawn (int argc, const VALUE *argv) |
Identical to rb_f_exec(), except it spawns a child process instead of replacing the current one. | |
rb_pid_t | rb_spawn_err (int argc, const VALUE *argv, char *errbuf, size_t buflen) |
Identical to rb_spawn(), except you can additionally know the detailed situation in case of abnormal parturitions. | |
VALUE | rb_proc_times (VALUE _) |
Gathers info about resources consumed by the current process. | |
VALUE | rb_detach_process (rb_pid_t pid) |
"Detaches" a subprocess. |
Public APIs related to rb_mProcess.
Definition in file process.h.
VALUE rb_detach_process | ( | rb_pid_t | pid | ) |
"Detaches" a subprocess.
In POSIX systems every child processes that a process creates must be wait(2)-ed. A child process that died yet has not been waited so far is called a "zombie", which more or less consumes resources. This function automates reclamation of such processes. Once after this function successfully returns you can basically forget about the child process.
[in] | pid | Process to wait. |
Definition at line 1555 of file process.c.
Referenced by rb_detach_process(), and rb_proc_times().
Replaces the current process by running the given external command.
This is the implementation of Kernel#exec.
[in] | argc | Number of objects in argv. |
[in] | argv | Command and its options to execute. |
rb_eTypeError | Invalid options e.g. non-String argv. |
rb_eArgError | Invalid options e.g. redirection cycle. |
rb_eNotImpError | Not implemented e.g. no `setuid(2)`. |
rb_eRuntimeError | `Process::UID.switch` in operation. |
rb_eSystemCallError | `execve(2)` failed. |
VALUE rb_last_status_get | ( | void | ) |
void rb_last_status_set | ( | int | status, |
rb_pid_t | pid ) |
Sets the "last status", or the $?.
[in] | status | The termination status, as defined in waitpid(3posix). |
[in] | pid | The last child of the current process. |
Definition at line 682 of file process.c.
Referenced by rb_last_status_set().
int rb_proc_exec | ( | const char * | cmd | ) |
Executes a shell command.
[in] | cmd | Passed to the shell. |
-1 | Something prevented the command execution. |
Definition at line 1801 of file process.c.
Referenced by rb_proc_exec().
Gathers info about resources consumed by the current process.
[in] | _ | Not used. Pass anything. |
VALUE rb_process_status_wait | ( | rb_pid_t | pid, |
int | flags ) |
Wait for the specified process to terminate, reap it, and return its status.
[in] | pid | The process ID to wait for. |
[in] | flags | The flags to pass to waitpid(2). |
Definition at line 1198 of file process.c.
Referenced by rb_process_status_wait(), and rb_waitpid().
rb_pid_t rb_spawn | ( | int | argc, |
const VALUE * | argv ) |
Identical to rb_f_exec(), except it spawns a child process instead of replacing the current one.
[in] | argc | Number of objects in argv. |
[in] | argv | Command and its options to execute. |
rb_eTypeError | Invalid options e.g. non-String argv. |
rb_eArgError | Invalid options e.g. redirection cycle. |
rb_eNotImpError | Not implemented e.g. no `setuid(2)`. |
rb_eRuntimeError | `Process::UID.switch` in operation. |
-1 | Child process died for some reason. |
otherwise | The ID of the born child. |
Definition at line 4722 of file process.c.
Referenced by rb_spawn().
rb_pid_t rb_spawn_err | ( | int | argc, |
const VALUE * | argv, | ||
char * | errbuf, | ||
size_t | buflen ) |
Identical to rb_spawn(), except you can additionally know the detailed situation in case of abnormal parturitions.
[in] | argc | Number of objects in argv. |
[in] | argv | Command and its options to execute. |
[out] | errbuf | Error description write-back buffer. |
[in] | buflen | Number of bytes of errbuf, including NUL. |
rb_eTypeError | Invalid options e.g. non-String argv. |
rb_eArgError | Invalid options e.g. redirection cycle. |
rb_eNotImpError | Not implemented e.g. no `setuid(2)`. |
rb_eRuntimeError | `Process::UID.switch` in operation. |
-1 | Child process died for some reason. |
otherwise | The ID of the born child. |
Definition at line 4716 of file process.c.
Referenced by rb_spawn_err().
void rb_syswait | ( | rb_pid_t | pid | ) |
This is a shorthand of rb_waitpid without status and flags.
It has been like this since the very beginning. The initial revision already did the same thing. Not sure why, then, it has been named syswait. AFAIK this is different from how wait(3posix) works.
[in] | pid | Passed to rb_waitpid(). |
rb_pid_t rb_waitpid | ( | rb_pid_t | pid, |
int * | status, | ||
int | flags ) |
Waits for a process, with releasing GVL.
[in] | pid | Process ID. |
[out] | status | The wait status is filled back. |
[in] | flags | Wait options. |
-1 | System call failed, errno set. |
0 | WNOHANG but no waitable children. |
otherwise | A process ID that was wait()-ed. |
Definition at line 1271 of file process.c.
Referenced by rb_syswait(), and rb_waitpid().