From 095e6097d98b26b2cd242c579507b020da91f558 Mon Sep 17 00:00:00 2001 From: mukesh2006 Date: Thu, 28 Nov 2024 16:50:44 +0400 Subject: [PATCH] submit assignment --- examples/systemcalls/systemcalls.c | 101 +++++++++++++++++++++++++++-- testfile.txt | 1 + 2 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 testfile.txt diff --git a/examples/systemcalls/systemcalls.c b/examples/systemcalls/systemcalls.c index 6793970..ff7a48a 100644 --- a/examples/systemcalls/systemcalls.c +++ b/examples/systemcalls/systemcalls.c @@ -1,5 +1,10 @@ #include "systemcalls.h" +#include +#include +#include +#include +#define NO_ERROR 0 /** * @param cmd the command to execute with system() * @return true if the command in @param cmd was executed @@ -11,12 +16,25 @@ bool do_system(const char *cmd) { /* - * TODO add your code here * Call the system() function with the command set in the cmd * and return a boolean true if the system() call completed with success * or false() if it returned a failure */ + int8_t system_return=system(cmd); + + if(NO_ERROR!=system_return) + { + return false; + } + + if ((WEXITSTATUS(system_return) == 0) && WIFEXITED(system_return) ) + { + printf("\nsystem() terminated gracefully\n"); + return true; + } + + return true; } @@ -40,6 +58,7 @@ bool do_exec(int count, ...) va_start(args, count); char * command[count+1]; int i; + bool returnVlaue = false; for(i=0; i 0){ + // int status; + + if (waitpid(pid,&status,0) == -1){ + return false; + } + + } + + va_end(args); - return true; + return WIFEXITED(status) && (WEXITSTATUS(status) == 0) ; } diff --git a/testfile.txt b/testfile.txt new file mode 100644 index 0000000..bc0fcd5 --- /dev/null +++ b/testfile.txt @@ -0,0 +1 @@ +home is $HOME