Created
May 21, 2015 04:10
-
-
Save kazuho/0c233e6f86d27d6e4f09 to your computer and use it in GitHub Desktop.
on Linux, posix_spawnp succeeds even if the executable does not exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <errno.h> | |
#include <spawn.h> | |
#include <stdio.h> | |
#include <string.h> | |
int main(void) | |
{ | |
extern char **environ; | |
char *args[] = {"nexist", NULL}; | |
pid_t pid; | |
if ((errno = posix_spawnp(&pid, args[0], NULL, NULL, args, environ)) != 0) { | |
fprintf(stderr, "failed to spawn %s:%s\n", args[0], strerror(errno)); | |
return 1; | |
} | |
fprintf(stderr, "successfully spawned %s\n", args[0]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment