running ls in a "for"
Hello , I wish to run simply command like ls into a boucle for (to do other applications)
but I didn't succeed, what should i do
and thank you
my code is:
#include <stdio.h>
#include <memory.h>
#include <unistd.h>
int main(int argc, char **argv)
{
/* create the pipe */
int i, *status = 0;
char *parmList[] = { "ls", "-l", NULL };
/* create the child */
int pid;
if ((pid = fork()) < 0) {
printf("fork failed\n");
return 2;
}
if (pid == 0) {
/* child */
for (i = 1; i < 10; i++)
execvp("ls", parmList);
printf("ls failed"); /* if execlp returns, it's an error */
return 3;
} else {
/* parent */
printf("status parent avant est %d \n", status);
waitpid(pid, &status, 0);
printf("status parent apres est %d \n", status);
return 4;
}
return 0;
}
|