Sponsored Content
Top Forums UNIX for Dummies Questions & Answers how to access files via their descriptors? Post 302282523 by Corona688 on Saturday 31st of January 2009 01:57:28 PM
Old 01-31-2009
To get a (new) file descriptor to do anything with you must first call open()*, which takes a filename. So yes, to open a file, you need a filename; the act of opening a file creates a file descriptor to represent that, the same way that running a program creates a new process ID to represent that.

Files are rather different from processes though, in that the PID is fundamental, and systemwide. The filename a process was ran with really isn't relevant since
a) If you have 4 xterms doing different things, you can't tell them apart by what file you ran
b) Lots of processes clone themselves, instead of loading new programs

So the PID is really the only way to identify processes. Commands like killall just trawl through the system's big list of PID's for you.

It's the files themselves that're unusual, and the ways you can use them, not the ways they're opened. There's several kinds of files:
  • Ordinary files, just blocks of data like you'd expect.
  • Symbolic links, a kind of special file that leads to a different file or directory sort of like a hyperlink leads to a website.
  • Hard links, where the same file is literally in two entirely seperate places. They have to be on the same partition, and share the same inode.
  • Named pipes aka FIFOs, where data written into the file by one process just gets pumped into whatever process is reading it.
  • Domain sockets, a kind of beefed-up version of named pipes that adds things like the ability for one server to talk to many clients over it.
  • Device files, which literally represent some hardware device or system-provided data source. 'dd if=/dev/random of=/dev/dsp' will read random data from the kernel and hurl it into your sound device on Linux systems with OSS compatibility...

You can also use FD's that have already been opened for you. The FD's 0, 1, and 2 are usually provided for you, where 0 represents the input stream(keyboard, for a console), 1 represents the output stream(the console display, for a console), and 2 represents error message output(also the console display). You can rearrange them how you please, having input coming from a file instead of console and having output going into a file or into another process etc etc etc.

* Okay, socket() and pipe() make FDs too, but have nothing to do with files on disk.

Last edited by Corona688; 01-31-2009 at 03:17 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help to access/mount so to access folder/files on a Remote System using Linux OS

Hi I need to access files from a specific folder of a Linux system from an another Linux System Remotely. I know how to, Export a folder on One SCO System & can access the same by using Import via., NFS in the Sco Unix SVR4 System using the scoadmin utility. Also, I know to use mount -t ... (2 Replies)
Discussion started by: S.Vishwanath
2 Replies

2. Programming

File Descriptors

Hi, I have written a daemon process, to perform certain operations in the background. For this I have to close, the open file descriptors, Does anybody know how to find out the number of open file descriptors ? Thanks in Advance, Sheetal (2 Replies)
Discussion started by: s_chordia
2 Replies

3. UNIX for Advanced & Expert Users

File Descriptors

Hello all, A few questions on file descriptors ... scenario : Sun Ultra 30 with Sun OS 5.5.1 , E250 with Solaris 2.6 In one of my servers, the file descriptor status from the soft limit and hard limits are 64 and 1024 respectively for root user. Is the soft limit (64) represents the... (3 Replies)
Discussion started by: shibz
3 Replies

4. UNIX for Dummies Questions & Answers

file descriptors

i m trying to learn processes in unix and i've been reading this but i don't quite get it. its regarding file descriptors. : each is a part of file pointers, they point to another area. indexes into an Operating system maintained table called "file descriptor table". one table per process. may... (3 Replies)
Discussion started by: a25khan
3 Replies

5. Programming

Sockets and File descriptors

I am in a Systems programming class this semester, and our current project is to write a program utilizing sockets and fork. For the project, I decided to make my own instant messaging program. I have the code completed, but I have a problem that keeps old clients from communicating with new... (3 Replies)
Discussion started by: gstlouis
3 Replies

6. UNIX for Dummies Questions & Answers

how to list the files using File Descriptors

hello, I have written a script named listall.sh with the following codes init. #!/bin/bash PATH="/proj/cmon/$1" echo $PATH if ; then echo "Usage: $0 ***" exit 1 else ls -l $PATH/*.sc fi Here there are 3 subdirectories (namely - src, data and jobs)under /proj/cmon, so... (2 Replies)
Discussion started by: shyjuezy
2 Replies

7. UNIX for Dummies Questions & Answers

Semaphores and File Descriptors

What is the difference between a file descriptor and a semaphore? My basic understanding is: - a file descriptor is a small positive integer that the system uses instead of the file name to identify an open file or socket. - a semaphore is a variable with a value that indicates the... (1 Reply)
Discussion started by: Mr_Webster
1 Replies

8. UNIX for Dummies Questions & Answers

kernel giving access for multiple users to access files

hi all, i want to know y kernel is giving access for multiple users to access a file when one user may be the owner is executing that file. Because other user can manipulate that file when the other user is executing that file, it will give the unexpected result to owner . plz help me... (1 Reply)
Discussion started by: jimmyuk
1 Replies

9. Shell Programming and Scripting

How to access files from different directories and to perform search action in those files?

Hi, I want to access files from different directories (for example: /home/dir1/file1 , /home/dir2/file2 ...) Like this i have to access these files(file1, file2...). (3 Replies)
Discussion started by: bangarukannan
3 Replies

10. Shell Programming and Scripting

Read loop from two files using descriptors

What I would like to do is read each line in the atdinfile: A sample atdinfile would look like this: 651 652 653 654 655 656 657 658 659 660 661 664 665 666 667 668 (5 Replies)
Discussion started by: woodson2
5 Replies
posix_openpt(3C)														  posix_openpt(3C)

NAME
posix_openpt() - open a pseudo-terminal master device SYNOPSIS
Parameters oflag indicates the file status flags and file access modes of the open file description. Values for oflag are constructed by a bit- wise-inclusive OR of flags from the following list, defined in Open for reading and writing. If set will not cause the terminal device to become the controlling terminal for the process. DESCRIPTION
The function establishes a connection between a master device for a pseudo-terminal and a file descriptor. This file descriptor can be used to refer that device. The file status flags and file access modes of the opened file descriptor will be set according to the value of oflag. RETURN VALUE
Upon successful completion opens a master pseudo-terminal device and returns a non-negative integer representing the lowest numbered unused file descriptor. Otherwise, returns -1 and is set to indicate the error. ERRORS
On failure sets one of the following values for OPEN_MAX file descriptors are currently open in the calling process. The maximum allowable number of files are currently open on the system. The value of oflag is not valid. Out of pseudo-terminal resources. Out of STREAMS resources. AUTHOR
was developed by HP. SEE ALSO
open(2), grantpt(3C), ptsname(3C), unlockpt(3C), ptm(7), pts(7). posix_openpt(3C)
All times are GMT -4. The time now is 05:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy