Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Created September 5, 2023 05:20
Show Gist options
  • Save kjunichi/016626235a5c261acf4548c900e486ca to your computer and use it in GitHub Desktop.
Save kjunichi/016626235a5c261acf4548c900e486ca to your computer and use it in GitHub Desktop.
#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