Skip to content

Instantly share code, notes, and snippets.

@tmlbl
Created June 9, 2018 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmlbl/d61ad03890867aec8fcabcfe59683e8a to your computer and use it in GitHub Desktop.
Save tmlbl/d61ad03890867aec8fcabcfe59683e8a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
typedef struct widget {
double value;
} widget;
void printval(int pid, double val)
{
printf("pid: %d value: %f\n", pid, val);
}
void split(widget *w)
{
int pid = fork();
if (pid) {
w->value = 0.2;
printval(pid, w->value);
sleep(1);
} else {
sleep(1);
printval(pid, w->value);
}
}
int main()
{
widget w;
split(&w);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment