From 6d264ed1ca292019f9c5b2ec3bf1d012954934e2 Mon Sep 17 00:00:00 2001 From: Bill Sun Date: Tue, 13 Sep 2016 16:42:32 +0800 Subject: [PATCH] child process exit when exec failed! --- wshell.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wshell.c b/wshell.c index f03d8f0..df94ca1 100644 --- a/wshell.c +++ b/wshell.c @@ -63,6 +63,7 @@ void proc(void) while(TRUE) { int pipe_fd[2],in_fd,out_fd; + int ret; type_prompt(prompt); ParaNum = read_command(&command,parameters,prompt); if(-1 == ParaNum) @@ -89,7 +90,12 @@ void proc(void) close(fileno(stdin)); dup2(pipe_fd[0], fileno(stdin)); close(pipe_fd[0]); - execvp(info.command2,info.parameters2); + ret = execvp(info.command2,info.parameters2); + if(ret < 0) + { + perror("command error"); + exit(-1); + } } else { @@ -164,7 +170,12 @@ void proc(void) dup2(in_fd, fileno(stdin)); close(in_fd); } - execvp(command,parameters); + ret = execvp(command,parameters); + if(ret < 0) + { + perror("command error"); + exit(-1); + } } } free(parameters);