lkml.org 
[lkml]   [2000]   [Nov]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectbug in count_open_files() or a strange granularity?
Hi,

A simple experiment:

a) insert a code like this in the open() routine of some driver:

struct files_struct *files = current->files;
extern int count_open_files(struct files_struct *, int);

printk(KERN_ERR "%s has %d files open\n",
current->comm, count_open_files(files, files->max_fdset));

b) write a program that opens that device and sleeps indefinitely. Run it,
you will see:

op has 32 files open

c) # lsof -p 659 | nl
1 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
2 op 659 tigran cwd DIR 3,6 4096 225730
/home/tigran/C/files
3 op 659 tigran rtd DIR 3,6 4096 2 /
4 op 659 tigran txt REG 3,6 14142 225732
/home/tigran/C/files/op
5 op 659 tigran mem REG 3,6 434945 295227
/lib/ld-2.1.92.so
6 op 659 tigran mem REG 3,6 4776568 295234
/lib/libc-2.1.92.so
7 op 659 tigran 0u CHR 4,9 348027 /dev/tty9
8 op 659 tigran 1u CHR 4,9 348027 /dev/tty9
9 op 659 tigran 2u CHR 4,9 348027 /dev/tty9
10 op 659 tigran 3r CHR 10,184 98313
/dev/cpu/microcode

so, we see that the process has only 9 files open and yet
count_open_files() claims there are 32. Is this a bug of
count_open_files() or is this a minimal granularity (because there are 32
builtin descriptors in files_struct->fd_array[])?

I know that there is no problem due to the way it is called in
copy_files() -- it would only be above 32. But for what I want to use it,
I need the _correct_ number of open file descriptors and not some "rounded
up to 32" one.

(kernel assumed test12-pre2)

Regards,
Tigran


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:47    [W:0.125 / U:0.340 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site