注:初期バージョンには、結果に影響するコピー アンド ペーストのバグがありました。今修正しました。
試してみて、基本的に、私は書きました
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[]){
int fd1 = open("/etc/passwd",O_RDONLY);
int fd2 = open("/etc/passwd",O_RDONLY);
printf("%d %d\n",fd1,fd2);
printf("FD1 position = %d\n", lseek(fd1,0,SEEK_CUR));
printf("FD2 position = %d\n", lseek(fd2,0,SEEK_END));
printf("FD1 position = %d\n", lseek(fd1,0,SEEK_CUR));
}
どちらが返されますか
$ ./a.out
3 4
FD1 position = 0
FD2 position = 2888
FD1 position = 0
私のMac OS 10.5ボックスと、Scientific Linuxボックスで機能的に同じもの(のサイズのみが異なります/etc/passwd
)。
fd
数値的に異なる が返され、それぞれ独自の位置カーソルが返されることに気付くでしょう。