Question: can some one help me im getting Memcheck, a memory error detector in my code when i run in my shell #include #include #include #include
can some one help me im getting "Memcheck, a memory error detector" in my code when i run in my shell #include
#include
#include
#include
#include
#include
#define MAXINPUTSIZE
#define MAXARGS
void executecommandchar args
pidt pid;
int status;
pid fork;
if pid
if execvpargs args
perrorError executing command";
exitEXITFAILURE;
else if pid
perrorError forking process";
else
waitpidpid &status, ;
printfChild PID: d Exit Status: d
pid, WEXITSTATUSstatus;
void executepipedcommandschar args char args
int pipefd;
pidt pid pid;
int status status;
if pipepipefd
perrorPipe creation failed";
exitEXITFAILURE;
pid fork;
if pid
closepipefd;
duppipefd STDOUTFILENO;
closepipefd;
if execvpargs args
perrorError executing command";
exitEXITFAILURE;
else if pid
perrorError forking process";
else
pid fork;
if pid
closepipefd;
duppipefd STDINFILENO;
closepipefd;
if execvpargs args
perrorError executing command";
exitEXITFAILURE;
else if pid
perrorError forking process";
else
Parent process
closepipefd;
closepipefd;
waitpidpid &status;
waitpidpid &status;
printfChild PID: d Exit Status: d
pid WEXITSTATUSstatus;
printfChild PID: d Exit Status: d
pid WEXITSTATUSstatus;
int mainint argc, char argv
char inputMAXINPUTSIZE;
char argsMAXARGS;
char token;
const char delim;
const char pipedelim;
char argsMAXARGSNULL;
char argsMAXARGSNULL;
if argc
printfs argv;
else
printf;
while fgetsinput sizeofinput stdin NULL
if input
fprintfstderr "Error: Empty command
;
else
inputstrcspninput
;
if strstrinput pipedelim NULL
token strtokinput pipedelim;
int i ;
while token NULL && i MAXARGS
argsi token;
token strtokNULL delim;
i;
argsi NULL;
token strtokNULL pipedelim;
int j ;
while token NULL && j MAXARGS
argsj token;
token strtokNULL delim;
j;
argsj NULL;
executepipedcommandsargs args;
else
int i ;
token strtokinput delim;
while token NULL && i MAXARGS
argsi token;
token strtokNULL delim;
i;
argsi NULL;
if strcmpargs "exit"
break;
executecommandargs;
c
if argc
printfs argv;
else
printf;
return ;
its a C language
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
