Commit 21288949 authored by Son Pham's avatar Son Pham

Lab10.2 completed

parent 4e15f25b
No preview for this file type
......@@ -13,11 +13,11 @@
#define STRING_LENGTH 256 // String length
int status;
int main(int argc, char* argv[]) {
// Print the fun ASCII shell image
printf("\n");
pid_t pid;
int status;
printf("██╗███████╗██╗ ██╗███████╗██╗ ██╗\n");
printf("██║██╔════╝██║ ██║██╔════╝██║ ██║\n");
printf("██║███████╗███████║█████╗ ██║ ██║\n");
......@@ -37,7 +37,6 @@ int main(int argc, char* argv[]) {
// Read command line
fgets(s, sizeof(s), stdin); // Read 255 character upuntil the new line
printf("%s\n", s);
// Parse command line into a list of argument
char ** param_list = NULL;
......@@ -55,12 +54,19 @@ int main(int argc, char* argv[]) {
param_list[n_args] = 0;
// Spawn a child to execute command line
pid_t pid = Fork();
pid_t pid;
int status;
pid = Fork();
if (pid == 0) { // child process exec
int value = execv(param_list[0], param_list); // TODO: WRAPPER
exit(0);
} else { // Parent process
waitpid(pid, &status, 0);
waitpid(pid, &status, WEXITSTATUS(status));
if (status == 0) {
printf("[ishell: program terminated successfully]\n");
} else {
printf("[ishell: program terminated abnormally] [%d]\n");
}
}
}
}
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment