#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main (int argc, const char * argv[])
{
printf("start\n");
char *const parmList[] = {"/bin/ls", "-l", NULL};
execv("/bin/ls", parmList);
return 0;
}
I compiled with GCC4.2 Any ideas why this might crash? I’m not getting any error messages in xcode.
EDIT: user error. “crash” meant xcode froze when it ran the program. Pressing continue works fine.
That code runs and compiles fine in my environment, gcc 4.4.3 under Ubuntu 10. That leads me to believe that you have a different problem from the one you think you have 🙂
Try the following code to see if the actual
execis failing. If it is, it should tell you why. If it isn’t, then you won’t see thercoutput at all.Also check to make sure the
/bin/lsis what you expect it to be (an executable, not a script, for example).And it’s worth clarifying what you mean by “crash”. Is it just not producing any output? It it dumping a core file? Is it bringing your entire OS to its knees, causing a reboot?