Module lsh.pipeline.children
Representation of the running or exited child processes of a pipeline.
Functions
| new (pl) | Constructs a new children struct and runs the cmds defined in the pipeline instance. |
Output
| output | The output of a finished pipeline. |
Children methods
| type () | Returns the instance type. |
| kill (self, signal) | Sends a signal to all child processes. |
| ids (self) | Returns the array of OS-assigned process identifiers of all child processes. |
| wait (self) | Waits for all child processes to exit completely, returning their pstatus. |
| try_wait (self) | Attempts to collect the exit statuses of the child processes if they have already exited. |
| wait_with_output (self) | Waits for all child processes to exit and returns an output struct with the stdout and stderr handles of the pipeline. |
Functions
- new (pl)
-
Constructs a new children struct and runs the cmds
defined in the pipeline instance.
Each
childinstance keeps a clone of its cmd, so you can inspect it.You do not need to call this function directly. Use lsh.pipeline.run or lsh.pipeline.spawn.
Parameters:
- pl lsh.pipeline
Returns:
-
lsh.pipeline.children
children
Output
- output
-
The output of a finished pipeline.
The pipeline.output method and the wait_with_output method of a children instance return this table.
Fields:
Children methods
- type ()
-
Returns the instance type.
Returns:
-
the string
"children" - kill (self, signal)
-
Sends a signal to all child processes.
For the valid signal names, see lsh.cmd.child.kill.
Parameters:
- self lsh.pipeline.children
- signal string signal name
Returns:
-
bool
trueOr
- nil
- string error message
Usage:
local sh = require 'lsh' local children = sh.pipeline():add(sh.cmd('sleep', 10)):spawn() children:kill('term')
- ids (self)
-
Returns the array of OS-assigned process identifiers
of all child processes.
Not implemented yet.
Parameters:
- self lsh.pipeline.children
Returns:
-
table
array of process identifiers
selene: allow(unused_variable)
- wait (self)
-
Waits for all child processes to exit completely, returning
their pstatus.
After the first call, this function always returns the same value.
Parameters:
- self lsh.pipeline.children
Returns:
-
lsh.pipeline.pstatus
pstatus struct
- try_wait (self)
-
Attempts to collect the exit statuses of the
child processes if they have already exited.
This function does not block the calling thread. It only checks if the child processes exited.
If all child processes exited, it reaps the process IDs and returns pstatus. Later calls return the same pstatus. If the exit statuses are not available yet, it returns
false.Parameters:
- self lsh.pipeline.children
Returns:
-
lsh.pipeline.pstatus
pstatus struct
Or
-
false
Or
- nil
- string error message
- wait_with_output (self)
-
Waits for all child processes to exit and returns an output
struct with the stdout and stderr handles of the pipeline.
By default, stdin, stdout and stderr are inherited from the parent. To capture the output in output, set a memfd instance with
stdout(sh.memfd())orstderr(sh.memfd()).Parameters:
- self lsh.pipeline.children
Returns:
Or
- nil
- string error message