Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save kotaroito/9114784 to your computer and use it in GitHub Desktop.

Select an option

Save kotaroito/9114784 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "error.h"
int main(void)
{
int i;
int pid;
i = 1;
if ((pid = fork()) < 0) {
err_sys("fork");
}
else if ( pid == 0 ) {
i++; // not shared with the parent proc
exit(EXIT_SUCCESS);
}
waitpid(pid, NULL, 0);
printf("i=%d\n", i); // 1
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment