Created
November 21, 2023 06:45
-
-
Save kjunichi/1053fc17d448ef43ec1d80dae021188e 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) { | |
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