From 8bd25dd52fc67b09d6f9860fb75fa5fb0c369d22 Mon Sep 17 00:00:00 2001 From: Clarissa Gardea Coronado <119063795+clarissagardea@users.noreply.github.com> Date: Thu, 19 Oct 2023 21:48:54 -0600 Subject: [PATCH] Create A01569420 --- labs/03/A01569420 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 labs/03/A01569420 diff --git a/labs/03/A01569420 b/labs/03/A01569420 new file mode 100644 index 00000000..c9535556 --- /dev/null +++ b/labs/03/A01569420 @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +void execute_argument(char* argument) { + pid_t pid; + pid = fork(); + + if (pid < 0) { + fprintf(stderr, "Fork failed\n"); + return; + } else if (pid == 0) { + + execlp("ls", "-l", NULL); + fprintf(stderr, "Exec failed\n"); + return; + } else { + + int status; + waitpid(pid, &status, 0); + } +} + +int main() { + char argument[100]; + + while (1) { + printf("osh> ls"); + fgets(argument, sizeof(argument), stdin); + + + argument[strlen(argument) - 1] = '\0'; + + if (strcmp(argument, "exit") == 0) { + break; + } + + execute_argument(argument); + } + + return 0; +}