Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, Is it possible to get a file descriptor from the major and minor number. If so, how can this be done? I am trying to see if a port(eg ...
  1. #1
    Just Joined!
    Join Date
    Sep 2010
    Posts
    12

    Get File Descriptor from major and minor number

    Hi, Is it possible to get a file descriptor from the major and minor number. If so, how can this be done? I am trying to see if a port(eg ttyS2) is opened without using the fdopen or open or fopen functions.

    Or maybe the question I should be asking is, is there a way to get the file descriptor of file or port that as already been opened, without using the functions I mentioned above. These functions reopens the port. I am trying to avoid that.

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    955
    Try the lsof command.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  3. #3
    Just Joined!
    Join Date
    Sep 2010
    Posts
    12
    the lsof command is terminal based. Is there a way to do this in C code
    Last edited by ptb4866; 11-15-2010 at 06:39 PM.

  4. #4
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    955
    Well, what about reading directory entries in /proc/PID/fdinfo? There's probably some function in libproc that does it more directly.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...