It's not looping since execve()
never returns. Also, this seems to be a very strange way to implement ls
: you should try to open a directory and read its contents (the list of files), not run another command, I would expect.
Look into the opendir()
and readdir()
functions, that's one way of actually implementing ls
.
And, also, please don't cast the return value of malloc()
in C.