exec
This commit is contained in:
parent
c6cab81a01
commit
5120f27b59
2 changed files with 34 additions and 17 deletions
BIN
shell2
BIN
shell2
Binary file not shown.
27
shell2.c
27
shell2.c
|
|
@ -1,10 +1,11 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <readline/readline.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <readline/history.h>
|
||||
#include <readline/readline.h>
|
||||
|
||||
#define clear() printf("\033[H\033[J")
|
||||
|
||||
|
|
@ -42,15 +43,31 @@ void print_dir() {
|
|||
printf("\nDir: %s", cwd);
|
||||
}
|
||||
|
||||
def execute(char** parsed) {
|
||||
void execute_args(char **parsed) {
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid == -1) {
|
||||
printf("\nFailed forking child..");
|
||||
return;
|
||||
} else if (pid == 0) {
|
||||
|
||||
if (execvp(parsed[0], parsed) < 0) {
|
||||
printf("\nCould not execute command..");
|
||||
}
|
||||
exit(0);
|
||||
} else {
|
||||
wait(NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void open_help() {
|
||||
puts("\n***Welcome to my shell help"
|
||||
"\n-Use the shell at your own risk..."
|
||||
"\nList of commands support:"
|
||||
"\n>cd"
|
||||
"\n>ls"
|
||||
"\n>exit"
|
||||
"\n>all other general commands available in UNIX shell");
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue