From aabbd212f6ba9a38999ea6e6f478bc8afae677d0 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Wed, 9 Oct 2024 13:59:59 +0200 Subject: sh: Add support for running commands in the background --- userland/minibox/utilities/sh/sh.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'userland/minibox/utilities/sh/sh.c') diff --git a/userland/minibox/utilities/sh/sh.c b/userland/minibox/utilities/sh/sh.c index 1505de3..e129044 100644 --- a/userland/minibox/utilities/sh/sh.c +++ b/userland/minibox/utilities/sh/sh.c @@ -7,6 +7,8 @@ #include #include +int active_processes = 0; + int execute_command(struct AST *ast, int input_fd); int execute_binary(struct AST *ast, int input_fd) { @@ -69,9 +71,20 @@ int execute_binary(struct AST *ast, int input_fd) { close(out); return execute_command(ast->pipe_rhs, slave_input); } + + active_processes++; + if (ast->should_background) { + return pid; + } + int rc; // FIXME: Should use waitpid ... when my OS supports that - wait(&rc); + for (; active_processes > 0;) { + if (-1 == wait(&rc)) { + continue; + } + active_processes--; + } return rc; } -- cgit v1.2.3