fork(1) download
  1.  
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <sys/types.h>
  6. #include <inttypes.h>
  7.  
  8.  
  9. int main(int argc, char **argv) {
  10. int fd1 = open("/etc/passwd", O_RDONLY);
  11. int fd2 = dup(fd1);
  12. char buf[19];
  13.  
  14. printf("fd#%d read: %d\n", read(fd1, buf, sizeof(buf)));
  15. printf("fd#%d: pos: %"PRIdPTR"\n", fd1, lseek(fd1, 0, SEEK_CUR));
  16. printf("fd#%d: pos: %"PRIdPTR"\n", fd2, lseek(fd2, 0, SEEK_CUR));
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
fd#19 read: 19
fd#3: pos: 19
fd#4: pos: 19