Created
September 5, 2023 05:20
-
-
Save kjunichi/016626235a5c261acf4548c900e486ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
int main(int argc, char **argv) { | |
//system("export HOGEHOGE=\"abc\""); | |
// setenv("HOGEHOGE","abd",1); | |
//putenv("HOGEHOGE=abz"); | |
printf("HOGEHOGE=%s\n", getenv("HOGEHOGE")); | |
int pid,status; | |
if((pid = fork()) < 0) { // 失敗時は -1 が返る | |
perror("fork failed"); | |
return 1; | |
} else if(pid==0){ | |
putenv("HOGEHOGE=abz"); | |
printf("son HOGEHOGE=%s\n",getenv("HOGEHOGE")); | |
} else { | |
waitpid(0, &status,0); | |
printf("parent HOGEHOGE=%s\n",getenv("HOGEHOGE")); | |
printf("finish!"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment