/* $ dcc set_status.c -o set_status $ dcc get_status.c -o get_status $ ./set_status Environment variable 'STATUS' has value 'great' $ */ #include #include #include #include #include // simple example of setting an environment variable int main(void) { // set environment variable STATUS setenv("STATUS", "great", 1); char *getenv_argv[] = {"./get_status", NULL}; pid_t pid; extern char **environ; int ret = posix_spawn(&pid, "./get_status", NULL, NULL, getenv_argv, environ); if (ret != 0) { errno = ret; perror("spawn"); return 1; } int exit_status; if (waitpid(pid, &exit_status, 0) == -1) { perror("waitpid"); exit(1); } // exit with whatever status s exited with return exit_status; }