47 lines
949 B
C
47 lines
949 B
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <sys/wait.h>
|
|
|
|
int main(int argc, char *argv[], char *arge[]) {
|
|
|
|
int codeTerm;
|
|
pid_t pidFils, idFils;
|
|
|
|
setenv("TEST", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1);
|
|
|
|
extern char **environ;
|
|
|
|
printf("environ père = \n");
|
|
for (char **p = environ; *p ; p++) {
|
|
printf("%s\n", *p);
|
|
}
|
|
|
|
pidFils=fork();
|
|
|
|
if (pidFils == -1) {
|
|
printf("Erreur fork\n");
|
|
exit(1);
|
|
}
|
|
|
|
if (pidFils == 0) {
|
|
printf("environ fils = \n");
|
|
for (char **p = arge; *p ; p++) {
|
|
printf("%s\n", *p);
|
|
}
|
|
}
|
|
else {
|
|
idFils=wait(&codeTerm);
|
|
|
|
if (idFils == -1){
|
|
perror("wait ");
|
|
exit(2);
|
|
}
|
|
|
|
if (WEXITSTATUS(codeTerm) != 0) {
|
|
printf("[%d] (%d)\n", WEXITSTATUS(codeTerm), idFils);
|
|
}
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
} |