From b046ce0212476f85ef276cfad84bf03881b3ce94 Mon Sep 17 00:00:00 2001 From: kh06089 <kh06089@ajou.ac.kr> Date: Thu, 3 May 2018 23:11:47 +0900 Subject: [PATCH] process creation --- src/built_in.c | 1 + src/commands.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/built_in.c b/src/built_in.c index d0a19fc..848b6f0 100644 --- a/src/built_in.c +++ b/src/built_in.c @@ -3,6 +3,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/wait.h> #include <unistd.h> #include <linux/limits.h> diff --git a/src/commands.c b/src/commands.c index 13e9c33..cf22df4 100644 --- a/src/commands.c +++ b/src/commands.c @@ -2,6 +2,15 @@ #include <stdlib.h> #include <string.h> #include <assert.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/wait.h> +#include <errno.h> +#include <pthread.h> + + #include "commands.h" #include "built_in.h" @@ -49,6 +58,23 @@ int evaluate_command(int n_commands, struct single_command (*commands)[512]) return 0; } else if (strcmp(com->argv[0], "exit") == 0) { return 1; + } + else if(com->argv[0] > 0) { + pid_t pid; + pid = fork(); + + switch(pid) + { + case -1 : + printf("fail\n"); + case 0 : + execv(com->argv[0], com->argv); + printf("exec fail\n"); + default : + wait((int*)0); + printf("complete\n"); + exit(0); + } } else { fprintf(stderr, "%s: command not found\n", com->argv[0]); return -1; -- GitLab