My mentor says to reproduce the system() function of Linux exactly as given in the man pages. I have written the below code. Could someone review this code and provide me any suggestions for improvising. I am a beginner. Thanks :).
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<error.h>
int my_system(const char *command);
int my_system(const char *command)
{
int ret = 0;
ret = execl("/bin/sh", "sh", "-c", command, (char *)NULL);
if (ret == -1)
error(1, 0, "error occcured in the execl() system call\n");
}
int main(int argc, char *argv[])
{
pid_t pid;
int ret;
int wstatus;
if (argc > 2)
error(1, 0, "Too many arguments\n");
pid = fork();
if (pid == -1) {
error(1, 0, "error in creating the sub-process\n");
} else if (pid == 0) {
ret = my_system(argv[1]);
} else {
wait(NULL);
}
return 0;
}
```