Skip to content

Instantly share code, notes, and snippets.

@hank
Created October 14, 2012 18:17
Show Gist options
  • Save hank/3889375 to your computer and use it in GitHub Desktop.
Save hank/3889375 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
int main()
{
char c;
pid_t pid;
char* filename = "foofile";
int fd = open(filename, O_RDWR);
if (fd == -1) {
/* Handle error */
}
read(fd, &c, 1);
printf("root process:%c\n",c);
pid = fork();
if (pid == -1) {
/* Handle error */
}
if (pid == 0) { /*child*/
pread(fd, &c, 1, 1);
printf("child:%c\n",c);
}
else { /*parent*/
pread(fd, &c, 1, 1);
printf("parent:%c\n",c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment