Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9324705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:39:58+00:00 2026-06-19T04:39:58+00:00

If I do: fd2 = open (file, O_RDONLY); and then fd1 = open (file,

  • 0

If I do:

fd2 = open ("file", O_RDONLY);

and then

fd1 = open ("file", O_RDONLY);

in the SAME PROCESS.
Do I get two different file pointers? I mean, can I move the “cursor” 100 bytes with fd2 and
fd1’s cursor will remain zero?

In addition, even if I open both for READONLY .. Does the filesystem creates TWO entries in the File table? or only one ? (Not the Inode table)

thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:40:00+00:00Added an answer on June 19, 2026 at 4:40 am

    Note: the initial version had a copy and paste bug which affects the result. Fixed now.

    On a try it and see basis, I wrote

    #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));
    }
    

    Which returns

    $ ./a.out 
    3 4
    FD1 position = 0
    FD2 position = 2888
    FD1 position = 0
    

    on my Mac OS 10.5 box and something functionally identical on a Scientific Linux box (differs only in the size of /etc/passwd).

    You’ll notice that you get back numerically different fds, and they each their own position cursor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, I open a file, then I use dup2 to copy the file descriptor.
I open a file using the system call open() . if ((fd2 = open(logFile,
i open a file and want to write something in it. The problem is
I have a parent process with two child processes fork'd off from it. I've
I'm trying to open a binary file using system calls, I cannot use functions
I know how monitor two file descriptors but how about 4 or 5 file
I'm trying to save a struct with a char* string into a file. struct
I create files 1.txt 2.txt and write some content into 1.txt . Then I
I'm using asynchronous pipes for inter-process communication (I removed error checks for simplification) int
OK I have a program that creates two pipes -> forks -> the child's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.