Created
October 14, 2012 18:17
-
-
Save hank/3889375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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