From da61a54719f3bf3d9bea8dfd9d6d8e58f550bff7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EC=9E=84=EC=98=81=EC=88=98?= <lys7120@ajou.ac.kr>
Date: Tue, 8 May 2018 19:03:50 +0900
Subject: [PATCH] /* signal handling correct */ /* process creation */

---
 src/commands.c        | 20 +++++++++++++++++++-
 src/signal_handlers.c |  2 --
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/commands.c b/src/commands.c
index 13e9c33..b66155b 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <unistd.h>
 
 #include "commands.h"
 #include "built_in.h"
@@ -49,8 +50,25 @@ 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] == '/'){
+      /* process creation */
+      int _pid = fork();
+
+      if (_pid == 0) {
+        /* execv system call's 1st parameter : all path */
+        /* If execv return '-1', ERROR. */
+        //printf("_pid = 0 \n");
+        if(execv(com->argv[0], com->argv) == -1){
+          fprintf(stderr, "Execv Error\n");
+          exit(0);
+        }
+      }
+      else if(_pid < 0) {
+        fprintf(stderr, "Fork Error\n");
+        return -1;
+      }
     } else {
-      fprintf(stderr, "%s: command not found\n", com->argv[0]);
+      fprintf(stderr, "%s : command not found\n", com->argv[0]);
       return -1;
     }
   }
diff --git a/src/signal_handlers.c b/src/signal_handlers.c
index aab0ba2..ac5caae 100644
--- a/src/signal_handlers.c
+++ b/src/signal_handlers.c
@@ -4,11 +4,9 @@
 void catch_sigint(int signalNo)
 {
   // Ctrl + C
-  signal(SIGINT, catch_sigint);
 }
 
 void catch_sigtstp(int signalNo)
 {
   // Ctrl + Z
-  signal(SIGTSTP, catch_sigtstp);
 }
-- 
GitLab