B
bite me if you can...
The man page of fork() says that the file descriptor are shared by
parent process & childern processes, so any operation of file
descriptor will affect them both.
But why the behavior of FILE doesn't like file descriptors?
This is my program, the result of operation of file descriptor is
ideal, but result of operation of FILE is amazing...
int fd=-1, pid;
FILE *fin=(FILE *)NULL;
fd=open("mem.tmp", O_RDWR);
fin=fopen("mem1.tmp", "r");
pid=fork();
if(pid) {
printf("(parent)\n");
printf("(parent) lseek(): %d\n", lseek(fd, 10, SEEK_SET));
fseek(fin, 10, SEEK_SET);
printf("(parent) ftell(): %d\n", ftell(fin));
}
else {
printf("(child)\n");
printf("(child)\n");
printf("(child) ftell(): %d\n", ftell(fin));
}
parent process & childern processes, so any operation of file
descriptor will affect them both.
But why the behavior of FILE doesn't like file descriptors?
This is my program, the result of operation of file descriptor is
ideal, but result of operation of FILE is amazing...
int fd=-1, pid;
FILE *fin=(FILE *)NULL;
fd=open("mem.tmp", O_RDWR);
fin=fopen("mem1.tmp", "r");
pid=fork();
if(pid) {
printf("(parent)\n");
printf("(parent) lseek(): %d\n", lseek(fd, 10, SEEK_SET));
fseek(fin, 10, SEEK_SET);
printf("(parent) ftell(): %d\n", ftell(fin));
}
else {
printf("(child)\n");
printf("(child)\n");
printf("(child) ftell(): %d\n", ftell(fin));
}