Skip to content

Instantly share code, notes, and snippets.

@hank
Created Oct 14, 2012
Embed
What would you like to do?
#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