diff --git a/.vscode/settings.json b/.vscode/settings.json index abc8474..d098913 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,12 @@ "loop.h": "c", "exec.h": "c" }, - "editor.tabSize": 2 + "editor.tabSize": 2, + "makefile.launchConfigurations": [ + { + "cwd": "/home/ir/dev/priCode/dish", + "binaryPath": "/home/ir/dev/priCode/dish/dish", + "binaryArgs": [] + } + ] } \ No newline at end of file diff --git a/Makefile b/Makefile index 17d7032..99c6dfd 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,21 @@ OBJ=main.o line.o loop.o exec.o CC=gcc CFLAGS= -O3 -Wall -all:debug - +all:release +r:release release:dish dish: $(OBJ) $(CC) $(CFLAGS) -o dish $(OBJ) +d: + make clean + make debug + debug: CFLAGS += -DDEBUG -g debug: dish +c: clean clean: rm -f $(OBJ) dish diff --git a/exec.c b/exec.c new file mode 100644 index 0000000..aa1d644 --- /dev/null +++ b/exec.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +int forkExec(char **args) { + pid_t pid; + int status; +#ifdef DEBUG + printf("debug: fork enter.\n"); +#endif + pid = fork(); + if (pid == 0) { + /* child process */ + if (execvp(args[0], args) == -1) { + perror("dish"); + exit(EXIT_FAILURE); + } + } else if (pid < 0) { + /* fork error */ + perror("dish"); + } else { + /* parent process: wait child process*/ + pid=wait(&status); + + } + return WEXITSTATUS(status); +} diff --git a/exec.h b/exec.h new file mode 100644 index 0000000..8b7f0ce --- /dev/null +++ b/exec.h @@ -0,0 +1,4 @@ +#ifndef __EXEC_H__ +#define __EXEC_H__ +int forkExec(char **args); +#endif \ No newline at end of file diff --git a/line.c b/line.c index 16eef5c..0733a50 100644 --- a/line.c +++ b/line.c @@ -17,7 +17,6 @@ char *readLine(void) { while (1) { // read a character c = getchar(); - printf("%s", &c); // repleace EOF with a null character and return if (c == EOF || c == '\n') { buffer[position] = '\0'; diff --git a/main.c b/main.c index 63696bd..7ca5c56 100644 --- a/main.c +++ b/main.c @@ -5,7 +5,7 @@ #include "loop.h" void intHandler(int dummy) { - printf("\nend!\n"); + printf("\nSIGINT exit.\n"); exit(EXIT_FAILURE); } @@ -13,7 +13,6 @@ int main(int argc, char *argv[]) { signal(SIGINT, intHandler); - printf("Hello, World!\n"); #ifdef DEBUG printf("DEBUG is defined\n"); #endif