问题描述
- linux下exec创建一个gcc进程来编译代码,如何判定编译是否成功?
-
代码在下面……1 #include
2 #include
3 #include
4 #include
5 #include
68 char * cmdargv[20] = {0};
9 int main(void)
10 {
11 pid_t pid;13 int retval;
16
17 while(1){20 if((pid = fork()) < 0){
21 perror("fork");
22 exit(-1);
23 }else if(pid == 0){
24 cmdargv[0] = "gcc";
25 cmdargv[1] = "./sleep.c";29 if(execvp("gcc",cmdargv)<0)
30 {
31 exit(-1);
32 }
33
34 exit(0);
35 }
36 wait(&retval);
37 }
38 }