나는 C의 유닉스 프로세스 관리에 익숙해지기 위해 미니 쉘을 작성하고있다. 명령 행에서 내용을 읽고 execlp를 통해이 인수를 시스템에 전달한다. 미니 쉘에서 strtok과 execlp
# include <stdio.h>
# include <stdlib.h>
# include <unistd.h>
#define MAXSIZE 100
char prompt[MAXSIZE];
int main(void)
{
pid_t pid;
printf("> ");
// read stuff
if (fgets(prompt, MAXSIZE, stdin) == NULL){
printf("Input validation error!");
abort();
}
// printf("DEBUG: %s" , prompt);
if (strcmp(prompt, "exit")==0) abort();
if ((pid=fork())<0){ // copy process
printf("Process error!");
abort();
}
if (pid==0){ // exec in son-prcess
char *command=(char*)strtok(prompt, " ");
execlp(command, command, 0); // overwrite memory
printf("Error, command not found!");
abort();
} else {
waitpid(pid, 0, 0);
}
}
는 사실이 그것을 것입니다,하지만 난
execlp()
에서 출력을하지 않습니다. 그 이유를 아는 사람이 있습니까?
"오류, 명령을 찾을 수 없습니다!" 인쇄 되든 안되니? – atomice