If you compiled with warnings, you'd notice that errno
is an int
, but you're trying to use it with printf
as a string, which means it is being used as a pointer. Memory address 0xFFFFFFF2 (or whatever the hexadecimal value of errno
is) probably isn't valid.
Aside from that, you need to end your execl
invocation with a NULL
pointer. Otherwise the function will keep thinking it has more command line arguments, all of which are strings, until the first NULL
it finds in memory or until the first invalid memory access, whichever comes first. Because copying the strings involves dereferencing a pointer, it will read the address made up of unknown bytes and attempt to dereference the pointer at that address repeatedly. If the pointer cannot be dereferenced, meaning accessing the address for reading data from it cannot be done, it will crash your program.
In the future, please compile with -Wall.