90s

Minimalist, customizable shell written in C99 with syntax highlighting
git clone https://codeberg.org/night0721/90s
Log | Files | Refs | README | LICENSE

commit 3cc6fb0d5a54f8b218ab191a6dbd72b673e50f88
parent d9f5d29dda4972b80d387929b8f196894e26a1bb
Author: night0721 <[email protected]>
Date:   Thu,  8 Feb 2024 12:31:57 +0000

fix waitpid

Diffstat:
Mcommands.c | 16+++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/commands.c b/commands.c @@ -157,16 +157,22 @@ int execute(char **args) { if (args[0] == NULL) { // An empty command was entered. return 1; } - + + // prioritize builtin commands for (int i = 0; i < num_builtins(); i++) { if (strcmp(args[0], builtin_cmds[i]) == 0) { return (*builtin_func[i])(args); } } + /* + while (*args) { + + } + */ + pid_t pid; - pid_t pid = fork(); int status; - if (pid == 0) { + if ((pid = fork()) == 0) { // Child process if (execvp(args[0], args) == -1) { if (errno == ENOENT) { @@ -178,9 +184,9 @@ int execute(char **args) { perror("fork failed"); } else { // Parent process - while (!WIFEXITED(status) && !WIFSIGNALED(status)) { + do { waitpid(pid, &status, WUNTRACED); // wait child to be exited to return to prompt - } + } while (!WIFEXITED(status) && !WIFSIGNALED(status)); } return 1;