Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Created November 21, 2023 06:45
Show Gist options
  • Save kjunichi/1053fc17d448ef43ec1d80dae021188e to your computer and use it in GitHub Desktop.
Save kjunichi/1053fc17d448ef43ec1d80dae021188e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
FILE *fp;
char buf[BUFSIZ];
system("echo \"OGEHOGE\">test.txt");
fp = fopen("./test.txt","rb");
fgets(buf, BUFSIZ,fp);
printf(buf);
// 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