Starting processes v0.1.0
SpawnFileActions
pub struct SpawnFileActions {
// private fields
}
Room for a posix_spawn_file_actions_t, which each C library sizes its own way and none larger than this.
Only ever passed by address to the posix_spawn_file_actions_* calls, which initialize and read it.
Constructors
SpawnFileActions
pub func SpawnFileActions() -> SpawnFileActions
Zeroed storage for posix_spawn_file_actions_init to initialize.
Returns: the storage
F_SETFD
pub const F_SETFD: int32 = 2;
F_SETFD: the fcntl command that sets a descriptor's flags.
FD_CLOEXEC
pub const FD_CLOEXEC: int32 = 1;
FD_CLOEXEC: close the descriptor when the process starts another program.
WNOHANG
pub const WNOHANG: int32 = 1;
WNOHANG: have waitpid return at once when the child has not finished.
SIGKILL
pub const SIGKILL: int32 = 9;
SIGKILL: the signal that ends a process at once and cannot be caught.
posix_spawnp
pub extern func posix_spawnp(
pid: *var int32,
file: *char8,
fileActions: *SpawnFileActions,
attributes: *opaque,
arguments: **char8,
environment: **char8
) -> int32
Starts file, found through PATH when it has no slash, as a child process.
See also: https://man7.org/linux/man-pages/man3/posix_spawn.3.html
Parameters
| Name | Type | Description |
|---|---|---|
pid | *var int32 | receives the child's process identifier |
file | *char8 | the program, NUL-terminated |
fileActions | *SpawnFileActions | the descriptor and directory setup to run in the child first, or null |
attributes | *opaque | spawn attributes, or null for the defaults |
arguments | **char8 | the argument vector, its first entry the program's name, ended by null |
environment | **char8 | the environment, NAME=VALUE entries ended by null |
Returns: zero, or an error number
posix_spawn_file_actions_init
pub extern func posix_spawn_file_actions_init(actions: *var SpawnFileActions) -> int32
Initializes an empty list of file actions.
See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_init.3.html
Parameters
| Name | Type | Description |
|---|---|---|
actions | *var SpawnFileActions | the storage to initialize |
Returns: zero, or an error number
posix_spawn_file_actions_destroy
pub extern func posix_spawn_file_actions_destroy(actions: *var SpawnFileActions) -> int32
Releases what posix_spawn_file_actions_init and the actions added since set up.
See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_destroy.3.html
Parameters
| Name | Type | Description |
|---|---|---|
actions | *var SpawnFileActions | initialized file actions |
Returns: zero, or an error number
posix_spawn_file_actions_adddup2
pub extern func posix_spawn_file_actions_adddup2(
actions: *var SpawnFileActions,
fd: int32,
newFd: int32
) -> int32
Adds an action duplicating fd onto newFd in the child.
See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_adddup2.3.html
Parameters
| Name | Type | Description |
|---|---|---|
actions | *var SpawnFileActions | initialized file actions |
fd | int32 | the descriptor to duplicate |
newFd | int32 | the descriptor it becomes |
Returns: zero, or an error number
posix_spawn_file_actions_addopen
pub extern func posix_spawn_file_actions_addopen(
actions: *var SpawnFileActions,
fd: int32,
path: *char8,
flags: int32,
mode: FileMode
) -> int32
Adds an action opening path as fd in the child.
See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_addopen.3.html
Parameters
| Name | Type | Description |
|---|---|---|
actions | *var SpawnFileActions | initialized file actions |
fd | int32 | the descriptor the file becomes |
path | *char8 | the file, NUL-terminated |
flags | int32 | the open flags |
mode | FileMode | the permissions of a file the open creates |
Returns: zero, or an error number
posix_spawn_file_actions_addchdir_np
pub extern func posix_spawn_file_actions_addchdir_np(
actions: *var SpawnFileActions,
path: *char8
) -> int32
Adds an action changing the child's working directory to path.
See also: https://man7.org/linux/man-pages/man3/posix_spawn_file_actions_addchdir_np.3.html
Parameters
| Name | Type | Description |
|---|---|---|
actions | *var SpawnFileActions | initialized file actions |
path | *char8 | the directory, NUL-terminated |
Returns: zero, or an error number
waitpid
pub extern func waitpid(
pid: int32,
status: *var int32,
options: int32
) -> int32
Waits for a child to change state, and reports how it finished.
See also: https://man7.org/linux/man-pages/man2/waitpid.2.html
Parameters
| Name | Type | Description |
|---|---|---|
pid | int32 | the child's process identifier |
status | *var int32 | receives the encoded status |
options | int32 | zero to wait, or WNOHANG to return at once when the child is still running |
Returns: the child's identifier, zero with WNOHANG when it is still running, or -1 with the reason in errno
kill
pub extern func kill(pid: int32, signal: int32) -> int32
Sends a signal to a process.
See also: https://man7.org/linux/man-pages/man2/kill.2.html
Parameters
| Name | Type | Description |
|---|---|---|
pid | int32 | the process |
signal | int32 | the signal number, such as SIGKILL |
Returns: zero, or -1 with the reason in errno
fcntl
pub extern func fcntl(
fd: int32,
command: int32,
...
) -> int32
Performs a control operation on a descriptor, such as setting its flags with F_SETFD.
See also: https://man7.org/linux/man-pages/man2/fcntl.2.html
Parameters
| Name | Type | Description |
|---|---|---|
fd | int32 | the descriptor |
command | int32 | the operation |
... |
Returns: the operation's result, or -1 with the reason in errno
__errno_location
pub extern func __errno_location() -> *var int32
Returns the address of the calling thread's errno, where the C library calls above leave their reason.
See also: https://man7.org/linux/man-pages/man3/errno.3.html
Returns: the errno's address