Skip to content

Instantly share code, notes, and snippets.

@ryuichiueda
Created March 17, 2014 04:18
Show Gist options
  • Save ryuichiueda/9593919 to your computer and use it in GitHub Desktop.
Save ryuichiueda/9593919 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(){
int pid = fork(); //子の場合: 0, 親の場合: 子のPID
//子の処理
if (pid == 0){
while(1){
sleep(1);
puts("child");
}
exit(0);
}
//親の処理
while(1){
sleep(1);
puts("parent");
}
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment