Skip to content

Instantly share code, notes, and snippets.

@HayatoDoi
Created May 21, 2017 11:01
Show Gist options
  • Save HayatoDoi/bd37351eff13963c86bb901f6eef6f5d to your computer and use it in GitHub Desktop.
Save HayatoDoi/bd37351eff13963c86bb901f6eef6f5d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h> // pid_t, fork
#include <sys/types.h> // pid_t, fork
#include <sys/wait.h> // wait
int main(){
pid_t pid;
int swap = 0;
if( (pid = fork()) == 0 ){
sleep(2);
swap = 1;
printf("子 : %d [%p]\n",swap,&swap);
}
else{
wait(NULL); // 子プロセスが終わるのを待機する.
printf("親 : %d [%p]\n",swap,&swap);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment