#include #include #include #include #include #include extern char **environ; pid_t run_sleep () { pid_t pid; char *argv[] = { "sleep", "10", NULL }; int err = posix_spawnp (&pid, "/bin/sleep", NULL, NULL, argv, environ); if (err == 0) return pid; else { printf ("posix_spawnp: %s\n", strerror (err)); exit (1); } } int main () { int status; pid_t pid = run_sleep (); if (wait (&status) < 0) perror ("wait"); if (WIFEXITED (status)) printf ("sleep 10 exited normally with status %d\n", WEXITSTATUS (status)); else if (WIFSIGNALED (status)) printf ("sleep 10 exited due to signal %d\n", WTERMSIG (status)); else printf ("????\n"); }