|
this simple program supposed to run the command ls
but the output is 1 and 2.can someone explain to me why ls not working ?
#include <stdio.h>
main()
{
int pid,stat;
if((pid=fork())==0)
{
execl("/bin/","ls",NULL);
printf("1");
exit(1);
}
else
{
wait(&stat);
printf("2");
}
}
|
|
|
|
|
The first argument to execl should contain the full path to the executable you want to run:
execl("/bin/ls","ls",NULL);
|
|
|
|
|
i understant that if i have parameters i shoud write
execl("/bin/date", "date", "-u", NULL);
how can i write the same thing with execv ?
|
|
|
|
|
Also execl returns a value that can help you tell why it isn't working.
Such as '2' which seems to pretty much always mean that it couldn't find the file it needed to execute.
|
|
|
|