System call execve does not return with ls function System call execve does not return with ls function shell shell

System call execve does not return with ls function


In your code, in parse_command() function, you're doing

bzero(arguments, sizeof(char) * MAXARGS);

but at that point of time, arguments is not initialized or allocated memory. So essentially you're trying to write into uninitialized memory. This invokes undefined behaviour.

Same like that, without allocating memory to arguments, you're accessing arguments[0].

Note: As I already mentioned in my comments, do not cast the return value of malloc() and family.


C uses pass by value. That means that after the call to parse_command the value of arguments will still be undefined, since any assignments were made to the local copy. Instead of becoming a three-star programmer I would recommend that you have parse_command return the argument list instead:

char **parse_command(char *command){    char **arguments = malloc(...);    ...    return arguments;}

And in main:

arguments = parse_command(command);

Also look at Sourav Ghosh's answer as he points out some other bugs.