Skip to content

Instantly share code, notes, and snippets.

@kazuho
Created May 21, 2015 04:10
Show Gist options
  • Save kazuho/0c233e6f86d27d6e4f09 to your computer and use it in GitHub Desktop.
Save kazuho/0c233e6f86d27d6e4f09 to your computer and use it in GitHub Desktop.
on Linux, posix_spawnp succeeds even if the executable does not exist
#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