#include #include #include #include struct mydat { pthread_t pth; char **env; pid_t pid; int status; }; extern char **environ; void *callfunc(void *data) { struct mydat *dat = data; int pid; int i; printf("Pointer BEFORE THE FORK env is %p\n", dat->env); i = 0; while (dat->env[i]) { printf(" env[%d] is %s\n", i, dat->env[i]); i++; } pid = fork(); if (pid == 0) { int i; printf("This is the child\n"); printf("Pointer env is %p\n", dat->env); i = 0; while (dat->env[i]) { printf(" env[%d] is %s\n", i, dat->env[i]); i++; } exit(0); } else { int status; dat->pid = pid; waitpid(pid, &status, 0); dat->status = status; printf("Child exited with %d\n", WEXITSTATUS(status)); } } void newthread(struct mydat *dat) { if (pthread_create(&dat->pth, NULL, callfunc, dat)) { perror("Couldn't create thread\n"); return; } pthread_join(dat->pth, NULL); } int main(int argc, char **argv) { struct mydat *dat; int value1; int valueb1, valueb2; int fd1, fd2; char *env2[] = { "APPTESTRESULT=42", (char *)0 }; char *env[] = { (char *)0 }; dat = malloc(sizeof(struct mydat)); dat->env = env; newthread(dat); free(dat); }