0
execvp는())의구현() 대신에 대신 execvp는()의 난 execv와을 (구현하는 방법을 배우고 싶은
나는 execvp는을 (가지고있는 코드를 가지고)와 난 (execv와로 변환하려고)하지만 명령의 경로를 찾을 수 없어서 실패했습니다. 명령 내가 생각하는 파일의 경로를 얻을 수 있지만, 어떻게 내가이 코드 변환 할
execv와()에 그것을 구현할 수 있습니다 디렉토리 목록에 명령에 대한
if ((pid = fork()) < 0) { /* fork a child process */
printf("*** ERROR: forking child process failed\n");
exit(1);
}
else if (pid == 0) { /* for the child process: */
printf("hophop");
if (execv("/usr/bin/ls"+*args[0], args) < 0) { /* execute the command */
printf("*** ERROR: exec failed\n");
exit(1);
}
}
else { /* for the parent: */
while (wait(&status) != pid) /* wait for completion */
;
}
/** the steps are:
(1) fork a child process using fork()
(2) the child process will invoke execvp()
(3) if background == 0, the parent will wait,
otherwise it will invoke the setup() function again. */
다음 줄 : 'while (wait (& status)! = pid)'은 'wait (& status);'이어야합니다. – user3629249
'ls' 바이너리가 시스템의'/ usr/bin /'에 있는지 확인 하시겠습니까? '무엇'이 뭐래? – xbug
이 줄은 : '(execv ("/ usr/bin/ls"+ * args [0], args) <0) {'가 execv()에 올바른 형식을 보내지 않습니다. ls 명령에 대한 모든 매개 변수는 args에 있어야하며 args는 다음과 같이 정의됩니다. char ** args []; 그 배열의 마지막 항목은 NULL이어야합니다. – user3629249