Skip to content

Instantly share code, notes, and snippets.

@farktronix
Created July 22, 2010 06:22
Show Gist options
  • Save farktronix/485644 to your computer and use it in GitHub Desktop.
Save farktronix/485644 to your computer and use it in GitHub Desktop.
$ gcc-4.0 -arch x86_64 -o varg varg.c && ./varg
ERROR: execlp failed with errno 14: Bad address
Child process started with pid 51425
Parent process complete.
$ gcc-4.0 -arch i386 -o varg varg.c && ./varg
Child process started with pid 51452
Parent process complete.
Child started with 5 arguments.
$ gcc -arch x86_64 -o varg varg.c && echo "===="; ./varg
varg.c: In function ‘main’:
varg.c:39: warning: missing sentinel in function call
====
ERROR: execlp failed with errno 14: Bad address
Child process started with pid 51425
Parent process complete.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
int main (int argc, const char * argv[]) {
char *foo = "foo";
char *bar = "bar";
if (argc > 1) {
printf ("Child started with %d arguments.\n", argc);
exit(0);
}
int pid = -1;
switch (pid = vfork()) {
case -1:
printf("Something bad happened.\n");
break;
case 0:
execlp(argv[0], argv[0], "--foo", foo, "--bar", bar, 0);
printf("ERROR: execlp failed with errno %d: %s\n", errno, strerror(errno));
_exit(1);
break;
default:
printf("Child process started with pid %d\n", pid);
}
printf("Parent process complete.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment