mirror of
https://github.com/troglobit/libite.git
synced 2026-10-10 16:52:25 +07:00
runbg: new helper function inspired by the Infix project
The runbg() function is a delayed execvp() that has double-forked to the background (to not create zombies). It is useful for running commands in the background for APIs that need to return a reply, e.g. a NETCONF RPC to reboot the system. Compared to the original in Infix, this version double forks to reparent itself to PID 1 (init), closes all open files, including stdio. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+13
@@ -249,6 +249,19 @@ Generic Functions
|
||||
`delete`, it is now called `opt`. The APIs are 100% compatible if the
|
||||
value `1` was used.
|
||||
|
||||
- `runbg(cmd, delay)`
|
||||
|
||||
Run a command in the background, after delay microseconds, essentially
|
||||
a background `execvp()` with a delay. The function employs double-fork
|
||||
to prevent zombies and closes all open files, including stdio.
|
||||
|
||||
```C
|
||||
char *cmd[] = { "sh", "-c", "echo 'hej' >/tmp/foo", NULL};
|
||||
|
||||
runbg(cmd, 200000); /* Create /tmp/foo after 200 millisec */
|
||||
/* Execution continues here immediately */
|
||||
```
|
||||
|
||||
- `strmatch(str, list)`, `strnmatch(str, list, len)`
|
||||
|
||||
Find matching string in an array of strings. Returns index in array on
|
||||
|
||||
Reference in New Issue
Block a user