Sponsored Content
Top Forums Programming maximum number of times - a file can be opened Post 302068709 by Perderabo on Monday 20th of March 2006 01:54:26 PM
Old 03-20-2006
I can't explain why your attempt to raise your softlimit failed.

Each open of a file creates a file table entry. The size of the file table is a kernel tunable parameter called nfile. You need to look at your own kernel to see what that is. You won't be able to use all of the file table entries repeatedly opening some file. You will need to open a few other files just to set up your attempt. Each file table entry for a file increments a counter in the vnode for that file. If you increment it to far, it would wrap around. This might not stop you from opening the file some more, but it would not be a good thing. The size of the integer that holds nfile and the size of the reference count should be the same size integer thus preventing this problem. It may be cheating, but you can have an opened file without opening a file. There are various ways to "dup" a file descriptor. The dup'ed fd points to the same file table entry as the original fd. Unix traditionally limits pid's to 32,000 (but your kernel may have a different limit). So I guess the limit is 32000 * max-fd-per-process. But again, minus a few for the overhead of reaching the point where you could try this stunt.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

maximum number of input on solaris

Hi, Can anyone tell me what the maximum amount of input characters is on solaris command line? (standard ksh I think) (1 Reply)
Discussion started by: marcello
1 Replies

2. Shell Programming and Scripting

Counting Number of times a File is accessed

Hi, I need to count the number of times a script is accessed from within the script. Is it possible ? Example: I have a script called lo.sh and i execute the script for the first time, then the counter variable declared inside the lo.sh should increment by 1. For every execution the... (1 Reply)
Discussion started by: pathanjalireddy
1 Replies

3. Shell Programming and Scripting

Will the output file be opened and closed several times?

Hi, there, I wrote a script like this: #!/bin/bash #put something into a LIST for item in $LIST do cat $item >> /tmp/output done My question is that if I have 5 items in that LIST, should it be opened and closed every time when the ">>" works? So that file will be opened and... (7 Replies)
Discussion started by: koifans
7 Replies

4. Shell Programming and Scripting

TO find the word which occurs maximum number of times

Hi Folks !!!!!!!!!!!!!!!!!!! My Requirement is............. i have a input file: 501,501.chan 502,502.anand 503,503.biji 504,504.raja 505,505.chan 506,506.anand 507,507.chan and my o/p should be chan->3 i.e. the word which occurs maximum number of times in a file should be... (5 Replies)
Discussion started by: aajan
5 Replies

5. UNIX and Linux Applications

handling maximum number characters in an input file

Hi, Can anyone help me? An input file has three lines. Each line should only be 2098 as number of characters however line 2 of the input file has more than the maximum number of characters, it exceeded up to 4098. What should I do so that could handle maximum number of characters? that it could... (1 Reply)
Discussion started by: chrysSty
1 Replies

6. UNIX for Dummies Questions & Answers

maximum number of arguments

Hi, What is the maximum number of arguments that could be passed to zsh ? To find out that I tried a simple script. And the maximum number of arguments that could be passed turned out to be 23394 #! /bin/zsh arg=1 i=1 subIndex=23000 while do arg=$arg" "$i i=$(($i + 1))... (9 Replies)
Discussion started by: matrixmadhan
9 Replies

7. UNIX for Dummies Questions & Answers

ls - maximum number of files

what is the maximum number ls can list down (6 Replies)
Discussion started by: karnan
6 Replies

8. UNIX for Advanced & Expert Users

Number of files currently opened in linux

Hello, How do i check number of files currently opening in the linux server? Your help is highly appreciated. Thank you ---------- Post updated at 02:43 PM ---------- Previous update was at 02:19 PM ---------- never mind!! I got it. ---------- Post updated at 02:44 PM ---------- Previous... (3 Replies)
Discussion started by: govindts
3 Replies

9. UNIX for Dummies Questions & Answers

how to count number of times each word exist in a file

I'm trying to count the number of times each word in the file exist for example if the file has: today I have a lot to write, but I will not go for it. The main thing is that today I am looking for a way to get each word in this file with a word count after it specifying that this word has... (4 Replies)
Discussion started by: shnkool
4 Replies

10. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies
DUP(2)							      BSD System Calls Manual							    DUP(2)

NAME
dup, dup2 -- duplicate an existing file descriptor SYNOPSIS
#include <unistd.h> int dup(int fildes); int dup2(int fildes, int fildes2); DESCRIPTION
dup() duplicates an existing object descriptor and returns its value to the calling process (fildes2 = dup(fildes)). The argument fildes is a small non-negative integer index in the per-process descriptor table. The value must be less than the size of the table, which is returned by getdtablesize(2). The new descriptor returned by the call is the lowest numbered descriptor currently not in use by the process. The object referenced by the descriptor does not distinguish between fildes and fildes2 in any way. Thus if fildes2 and fildes are duplicate references to an open file, read(2), write(2) and lseek(2) calls all move a single pointer into the file, and append mode, non-blocking I/O and asynchronous I/O options are shared between the references. If a separate pointer into the file is desired, a different object reference to the file must be obtained by issuing an additional open(2) call. The close-on-exec flag on the new file descriptor is unset. In dup2(), the value of the new descriptor fildes2 is specified. If fildes and fildes2 are equal, then dup2() just returns fildes2; no other changes are made to the existing descriptor. Otherwise, if descriptor fildes2 is already in use, it is first deallocated as if a close(2) call had been done first. RETURN VALUES
Upon successful completion, the new file descriptor is returned. Otherwise, a value of -1 is returned and the global integer variable errno is set to indicate the error. ERRORS
The dup() and dup2() system calls will fail if: [EBADF] fildes is not an active, valid file descriptor. [EINTR] Execution is interrupted by a signal. [EMFILE] Too many file descriptors are active. The dup2() system call will fail if: [EBADF] fildes2 is negative or greater than the maximum allowable number (see getdtablesize(2)). SEE ALSO
accept(2), close(2), fcntl(2), getdtablesize(2), open(2), pipe(2), socket(2), socketpair(2) STANDARDS
dup() and dup2() are expected to conform to IEEE Std 1003.1-1988 (``POSIX.1''). 4th Berkeley Distribution December 1, 2010 4th Berkeley Distribution
All times are GMT -4. The time now is 06:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy