lsコマンドのexecl()関数に引数を渡そうとしています。しかし、私が合格すると
/bin/ls -l -a
私のプログラムの引数として、execl()関数は最後の2つの引数を認識しません。それはなぜですか?コードは次のとおりです:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i,childpid;
if(argc!=4)
{
printf("you didn't provide any commandline arguments!\n");
return 0;
}
childpid=fork();
if(childpid<0)
{
printf("fork() failed\n");
return 0;
}
else
if(childpid==0)
{
printf("My ID %d\n\n",getpid());
execl(argv[1],argv[2], argv[3],NULL);
printf("If you can see this message be ware that Exec() failed!\n");
}
while(wait(NULL)>0);
printf("My ID %d, Parent ID %d, CHild ID %d\n", getpid(),getppid(),childpid);
return 0;
}
私はUbuntuを使用しています。
よろしく