0
execlが存在しないファイルを起動しようとしたときに返されたエラーを理解しようとしています。execlエラー==ファイルが存在しないときに "ファイルが存在する"
# include <stdio.h>
# include <assert.h>
# include <sys/types.h>
# include <sys/wait.h>
# include <unistd.h>
# include <stdlib.h>
int spawn1(char *, char *, char *);
int main(){
int i, t, tt, state;
for(i = 0; i < 10; i++){
t = spawn1("functiondoesntexist", "strange name", "argument");
if (t < 0){
perror("fork"); // fork error
break;
}
tt = wait(&state);
assert(tt == t);
if (state != 0){
perror("exec didn't work");
break;
}
}
return i != 10;
}
int spawn1(char * file, char * command, char * arg){
int t;
t = fork();
if (t < 0) // fork error
return -1;
if (t == 0){ // child
execl(file, command, arg, (void *)0);
exit(1);
}
// parent
return t;
}
エラーが返されます:
exec didn't work: File exists
なぜISNここ
はメインフォークを作成し、EXECLを起動しようとする機能のspawn1を呼び出し、この実験のために私のコードです「ファイルは存在しない」のようなものがありますか?