LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2006, 04:49 PM   #1
draksonije
LQ Newbie
 
Registered: Mar 2006
Posts: 2

Rep: Reputation: 0
Need help with writeing a new system call! What is a file descriptor?


Hi,
I need a to write a system call. My question is: "WHAT EXACTLY IS A FILE DESCRIPTOR??!?". My system call is supposed to returns a number of open files for a process identified by a pid and file desctiptor for each file used by a process. The system call should look like this:

int get_open_files(pid_t pid, int *count, int** fds); returnt value is error code or an integer greater then 0 if evrything worked fine.

Geting the count is not a problem. The problem is getting (int **fds)!!! I guess it can be found by looking into task_struct of a proces and then into struct files_struct *files whitin task_struct. There is a field struct file ** fd in files_struct. This is my best. I am stuck here. Please help me. Once again: What exactly is a file descriptor? Ideal answer shoul point out one or more fields form a certain structure. For example "A file desctiptor, you idiot, is: some_stuct->some_field1, some_struct->some_field2...)
Thanx a lot
Dragan
 
Old 03-22-2006, 12:14 AM   #2
smsundar
LQ Newbie
 
Registered: Dec 2005
Posts: 16
Blog Entries: 3

Rep: Reputation: 0
When you declare
FILE *fp;

and initalise fp = fopen(file,mode);
fopent will return a pointer (memory location of that file starting location).
that is know as file descriptor and it is of type unsigned int.

even you declare
int fp;
fp = open(file,mode,flag); or
fp = creat(file,mode,flag); or read write and so on...

in your declaration,
int get_open_files(pid_t pid, int *count, int** fds);

change it to
int get_open_files(pid_t pid, int *count, unsigned int** fds);

hope its wright now...

hope i have cleared your doubt?

Last edited by smsundar; 03-22-2006 at 12:23 AM.
 
Old 03-22-2006, 01:29 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by smsundar
When you declare
FILE *fp;

and initalise fp = fopen(file,mode);
fopent will return a pointer (memory location of that file starting location).
that is know as file descriptor and it is of type unsigned int.
Hmmm, no. That is known as a file pointer (as the fp name suggests), and is certainly not of type unsigned int but of type pointer to a structure.
Quote:
even you declare
int fp;
fp = open(file,mode,flag); or
fp = creat(file,mode,flag); or read write and so on...
You got it better here, but you should use "fd", not "fp" to avoid confusion.
Quote:
in your declaration,
int get_open_files(pid_t pid, int *count, int** fds);

change it to
int get_open_files(pid_t pid, int *count, unsigned int** fds);
That's optimistic, I do not expect a process with more than 2147483648 open files
Quote:
hope its wright now...

hope i have cleared your doubt?
Hope I've cleared yours.
I guess the OP is asking about file descriptors in the kernel, not in userspace.
 
Old 03-22-2006, 02:08 AM   #4
smsundar
LQ Newbie
 
Registered: Dec 2005
Posts: 16
Blog Entries: 3

Rep: Reputation: 0
Wondered about your reply.
Thanks for your corrections....
appreciating you
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the absolute path of file using file descriptor. appas Programming 7 01-19-2012 11:47 AM
File Descriptor 63 kshkid Programming 3 03-02-2006 11:41 AM
boot/System.map: Bad file descriptor pixie Fedora 16 03-01-2005 12:19 PM
apt-file returns nothing; 'bad file descriptor' overbored Debian 3 10-03-2004 09:13 PM
File descriptor lido Linux - Newbie 5 07-17-2003 11:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration