From e81502c9149b9f22cac0ec335dfd0c89df07b0d5 Mon Sep 17 00:00:00 2001 From: AdelaSolorio <117191525+AdelaSolorio@users.noreply.github.com> Date: Thu, 19 Oct 2023 22:29:33 -0600 Subject: [PATCH] Create A01637205.c --- labs/03/miTerminal.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 labs/03/miTerminal.c diff --git a/labs/03/miTerminal.c b/labs/03/miTerminal.c new file mode 100644 index 00000000..6318e9c2 --- /dev/null +++ b/labs/03/miTerminal.c @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include +#include + +int main() { + int option; + int pid; + + do { + + printf("Menu:\n"); + printf("1. ls: List directory contents\n"); + printf("2. pwd: Show full path of the current directory\n"); + printf("3. date: Show the system's date and time\n"); + printf("4. Exit the program\n"); + printf("Please select an option: "); + + scanf("%d", &option); + + switch (option) { + + //ls + case 1: + pid = fork(); + + if (pid == 0) { + execlp("/bin/ls", "ls", NULL); + + } else if (pid > 0) { + wait(NULL); + + } else { + printf("Error creating the child process.\n"); + } + break; + + //pwd + case 2: + pid = fork(); + + if (pid == 0) { + execlp("/bin/pwd", "pwd", NULL); + + } else if (pid > 0) { + wait(NULL); + + } else { + printf("Error creating the child process.\n"); + } + break; + + //date + case 3: + pid = fork(); + if (pid == 0) { + execlp("/bin/date", "date", NULL); + + } else if (pid > 0) { + wait(NULL); + + } else { + printf("Error creating the child process.\n"); + } + break; + + //exit + case 4: + printf("Exiting the program\n"); + break; + + + default: + printf("Option not valid. Please enter a valid option.\n"); + } + + } while (option != 4); + + return 0; +}