Close all file descriptors

How do i close all the open file descriptors, without knowing how many
descriptors are open.
Is it not bad to close a file descriptor which is not open.

0
ravi
7/25/2004 6:57:33 AM
comp.unix.programmer 10729 articles. 64 followers. kokososo56 (349) is leader. Post Follow

5 Replies
564 Views

Similar Articles

[PageSpeed] 59
ravi wrote:
> How do i close all the open file descriptors, without knowing how many
> descriptors are open.
> Is it not bad to close a file descriptor which is not open.

man getdtablesize

Use this information to go over al descriptors between 0 (or 3)
and the value returned by getdtablesize() call.

-- 
Lev Walkin
vlm@lionet.info
0
Lev
7/25/2004 7:08:29 AM
On Sun, 25 Jul 2004 00:08:29 -0700, Lev Walkin wrote:

> ravi wrote:
>> How do i close all the open file descriptors, without knowing how many
>> descriptors are open.
>> Is it not bad to close a file descriptor which is not open.
> 
> man getdtablesize
> 
> Use this information to go over al descriptors between 0 (or 3)
> and the value returned by getdtablesize() call.

Baad programming habits.

Much better to keep track of what you've opened, or use clone().
0
Viktor
7/25/2004 12:54:13 PM
Viktor Lofgren wrote:
> On Sun, 25 Jul 2004 00:08:29 -0700, Lev Walkin wrote:
> 
> 
>>ravi wrote:
>>
>>>How do i close all the open file descriptors, without knowing how many
>>>descriptors are open.
>>>Is it not bad to close a file descriptor which is not open.
>>
>>man getdtablesize
>>
>>Use this information to go over al descriptors between 0 (or 3)
>>and the value returned by getdtablesize() call.
> 
> 
> Baad programming habits.
> 
> Much better to keep track of what you've opened, or use clone().

If we're talking about programming practices, it might be even better
to use fcntl(, F_SETFD, &FD_CLOEXEC), in cases where exec() is planned
down the road.

However, neither "tracking what you've opened", nor "habitually setting
close-on-exec flag" are universally applicable in the real world programming.
The things is, many libraries (including libc) open file descriptors
"behind the scenes". If a program does not depend on any third-party
libraries and does not use certain libc functions (such as
openlog(3)/syslog(3), getpwnam(3), etc), then yes, keeping track is key.
Otherwise, just closing every possible file descriptor is just plain
better than closing certain ones which are accounted for, and hoping that
accounting was right and no other library opened shadow fds behind
the scenes.

-- 
Lev Walkin
vlm@lionet.info
0
Lev
7/25/2004 1:16:14 PM
On Sun, 25 Jul 2004, Viktor Lofgren wrote:

> Much better to keep track of what you've opened, or use clone().

Clone is not portable.

-- 
Rich Teer, SCNA, SCSA

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net
0
Rich
7/25/2004 7:45:22 PM
On Sat, 24 Jul 2004, ravi wrote:

> How do i close all the open file descriptors, without knowing how many
> descriptors are open.

If you're on a recent version of Solaris, closefrom() will
do what you want.

> Is it not bad to close a file descriptor which is not open.

Nope.  The worst that will happen is that you'll waste a few
ms of CPU time trying to close files that are not open.

-- 
Rich Teer, SCNA, SCSA

President,
Rite Online Inc.

Voice: +1 (250) 979-1638
URL: http://www.rite-online.net
0
Rich
7/25/2004 7:47:20 PM
Reply:
Similar Artilces:

writing binary files
I am trying to convert an ANSI encoded ASCII text file to a binary file. I have looked at the b2a_qp( data[, quotetabs, istext, header]) function at http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/python/lib/module-binascii.html but I am not sure if it will do what I need it to or how set it up to take the data. Also, the parts of this that really make it an issue is that the data is coming off of a DOS machine (so endian is a concern here right?) and is a rather large text file with a ton of scientific data points (from 500k to 5MB files). Any help would be greatly appreciated...

"Close match" regex
I was wondering if there were a built-in pattern finder to get a close match on strings. Our users are constantly omitting dashes, dots, and spaces from software release labels. And when you look at the list with intelligent eyes, you see it's obvious what they meant. software_version-2.4.5 = = software-version_245 You get the idea. Anyone have a regex solution? Thanks in advance Bill William Hymen wrote: > I was wondering if there were a built-in > pattern finder to get a close match on strings. I think there is some module that attempts to do it, but I don't know ...

image retrieval using automatic image annotation and region based inverted file
please anyone tell me,whether the topic image retrieval using automatic image annotation and region based inverted file can implement? ...

How to close a shell window automatically
In my AutoExec.sas I have: x copy C:\SASTextFiles\SASLog.txt C:\SASTextFiles\SASLogOld.txt; This works fine but the shell windows stays open. How do can make it close automatically after it has done the command? On 13 Sep, 17:21, mpa...@ODOT.ORG (Masoud Pajoh) wrote: > In my AutoExec.sas I have: > > x copy C:\SASTextFiles\SASLog.txt C:\SASTextFiles\SASLogOld.txt; > > This works fine but the shell windows stays open. > > How do can make it close automatically after it has done the command? Try XSYNC with NOXWAIT and run your commands as systask command ...

run compiled exe file on another machine #2
Dear All: I was told that "mclmcrrt76.dll" was not found when I try to run the exe file on another machine with no matlab in it. Could you give me some suggestions about how to fix the problem? Thanks a lot, Joey On Oct 28, 8:12 am, Joey <joey2...@gmail.com> wrote: > Dear All: > > I was told that "mclmcrrt76.dll" was not found when I try to run the > exe file on another machine with no matlab in it. Could you give me > some suggestions about how to fix the problem? > > Thanks a lot, > > Joey =================================== Joey: St...

Creating a file with $SIZE
Hi All, I would like create files of different size, taking size as user input. I need to check the data transfer rates from one network to another . In order to do this I will have to create files of diff size and work out. I am new to ruby Thanks, KK 2008/3/12, iPerfect <nkanthikiran@gmail.com>: > I would like create files of different size, taking size as user > input. I need to check the data transfer rates from one network to > another . In order to do this I will have to create files of diff size > and work out. I am new to ruby http://www.ruby-doc.org/docs/Prog...

Re: Finding Table names in an Access *.mdb file
Yes--set a sas/access libname to the mdb & then query the table names out of dictionary.tables w/proc sql. Like so: libname mdb ODBC required = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=C:\Documents and Settings\pardre1\Desktop\MENUReporter.mdb" ; proc sql ; create table mdb_tables as select memname from dictionary.tables where libname = 'MDB' ; select memname from mdb_tables ; quit ; Note that that gets you msaccess' system tables too--to screen those out, use this where clause: where libname = 'MDB' AND memname not l...

Problem referencing library file via project file
I am trying to link the webkit library file with my program. One way that works is to use: pragma Linker_Options ("-lwebkit-1.0"); in my source file. However I would like to specify this in the program's project file. I have tried: package Linker is for Default_Switches ("ada") use ("-lwebkit-1.0"); end Linker; but this seems to be ignored - I just get undefined reference messages from gnatlink. Please help! Robert Matthews On Sat, 30 Apr 2011 09:15:34 +0100, Robert Matthews wrote: > I am trying to link the webkit library file with my program. &g...

file permission
Hi there,i've got this problem i downloaded a pdf file from a win XP ,than copied to a USB mass storage msdos,opened my opensolaris laptop looked that file,but no chance to view it;so i've done a ls - la and it says rw just for root,so i moved to root but i had no chance to change permission. Do you know if i open that file with hexdump it would be possible to change the permissions? Thanks guys franzi <hazzino@gmail.com> writes: > Hi there,i've got this problem i downloaded a pdf file from a win > XP ,than copied to a USB mass storage msdos,opened my opensolaris &...

[ace-users] server closes connection
--0-348674199-1063197416=:85473 Content-Type: text/plain; charset=us-ascii Hi Ace-users, In a client-server application; when server closes connection , client gets -1 only one time and it prints it on screen. This works in Windows 2000 but when I try this in Solaris I see that " -1 "comes from server many times and client prints these messages.approximately, 21 times. Why do this happen?I use Reactor for select() mechanism . I think different select mechanism causes this. Is it possible that Solaris kernel sends -1 many times or what else? Thanks. Sincerely ---------------------...

Matlab closes down at launch
Does anyone knows why matlab 7 closes down at launch. Just to inform that my windows is Xp and my processor is AMD ...

Bug? File::Temp messing with @INC
Hi all, I've recently upgraded to perl 5.8.7 and noticed something that is quite annoying - File::Temp is fiddling with the order of the paths in @INC (or at least some library it loads is - haven't quite found the problematic code). Example: > perl -e 'use lib "/path/to/my/libs"; print join("\n", @INC), "\n"' /path/to/my/libs /usr/local/lib/perl5/site_perl/5.8.7/mach /usr/local/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl/5.8.5 /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.8.7/BSDPAN /usr/local/lib/perl5/5.8.7/mach /u...

closing and reusing streams
Dear all, for a bookproject that I'm working on I've inherited a large number of homemade style-files. The problem that I have is that they make heavy use of \@starttoc to write to files, and now the upper limit seems to be reached and I'm getting the dreaded "No room for a new \write" error. From previous postings I've learned that \@starttoc allocates a new stream and/or file number for each TOC, which might not be necessary. As a solution David Wilson (davidw@utopiatype.com) wrote (1999/07/02): > If you are allocating a separate > output stream for each t...

FAQ 5.29 How can I read in an entire file all at once? 466968
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.29: How can I read in an entire file all at once? Are you sure you want to read the entire file and store it in memory? If you mmap the file, you can virtually load the entire file into a string wi...

mex files #2
Hello, I am new to mex files. What I am trying to do is pass matlab structs (which themselves contain structs, i.e. X.Y.z.P would access an integer, X.Y.f.g would access a float, X.q(2) would access a double, etc.) into the mex gateway routine and then pull the data out and put it into corresponding C structs. is this an easy thing to do? Can someone give me an example? Any help is much appreciated. ...

Re: HP COBOL closing files. #2
Michael Baier wrote: >>> "KENT WALLACE" wrote: >>> I was coding in VB .NET and failed to close a file. I found that records >>> were missing from the end of the file, maybe 10. Because I had failed to >>> close the file, it failed to clear the buffer. >> >>This shouldn't be a problem in COBOL. COBOL automatically closes all files >>for you as part of normal run unit termination. >> >>Walter >> > > Yes and NO, > > I just learned, that there could be a problem with some files. ...

What are these files in my TEMP directory??
I couldn't for the life of me figure out why my cpu was telling me that my 37gig hard-drive was full, so I went poking around, and in my C:/Windows/TEMP folder, there were about 150 folders that each were title something like "tmp000076e8"...always starting with 'tmp', then some combination of letters and digits. Each folder contained a single file (with the same title as the folder it was in) in a format that my computer did not recognize that was between 180 and 400 MB in size!! Anyone know what these files were, and why my computer was creating and storing ...

One class per file for an Applet ?
An applet that I am writing works fine when run from my local drive in IE. However when run remotely from a website, I receive the following error. java.lang.ClassNotFoundException: Engine All my classes (over which there are around 20) are packed into a single file - Wobbles.class . The html file looks like this: <html> <body> <applet code=Wobbles.class width="460" height="330" > </applet> </body> </html> Should each class be in a separate file ? -Luke "Luke J Crook" <luke@NO-SPAM.balooga.com> wrote in message n...

"Error using save" with MAT files
Our program saves various arrays or cells into a few MAT files. We experience save problems with one of them when writing a given struct. We sometimes get: Error using save Error closing file... or Out Of Memory during serialization of the Subsystem Data Error using save Error closing file... but our PCs have 3Gb+ of RAM and when this happens, the 'memory' command reports at least 500Mb of available memory, so we suspect this "out of memory" error is actually a default message for a failing serialization. Is there any way to pre-validate an array or cells befo...

JavaMail POP3 folder.close() method close also store!
Hi @ll, I was wondering why I lose the connection to the mail store while retrieving information from it without calling the method store.close()! At the end I found out that the method folder.close(boolean) also close the store! Following you see the debug log of the JavaMail API: > C: QUIT > S: +OK POP3 server closing connection I really have to keep the connection alive to the server to get all messages at once from the mail store. But after closing the folder my client is disconnected :o( From my point of view it is not very correct that the API close the connecti...

File with hash inside it
I have a file containing the following info: { 'MGT6101' => { 'desc' => 'An examination of the tools and procedures used by organizations to attract, select, and retain employees within the context of the legal and regulatory environment.', 'title' => 'Managing Human Resources' }, 'MGT6015' => { 'desc' => 'The course covers cost estimation, standard costs, variable costing, relevant costs, transfer pricing, performance evaluation, cost of quality, and activity-based costing for service.', '...

No close (x) buttom for the access
Hi, Is it possible to remove the access-application close-button (X) Filip Not per se, but there are ways of preventing its use. See www.mvps.org/access/forms HTH - Turtle "Filips Benoit" <benoit.filips@pandora.be> wrote in message news:r4LTb.141$tH5.112751@phobos.telenet-ops.be... > Hi, > > Is it possible to remove the access-application close-button (X) > > Filip > > Yes, I found time ago (I can not remember where) this VBA code that makes Access "X" disabled; it works perfectly in Access 97 I did not try on newer versions: Put th...

find files
Hi all, how can I find file/s (within a path), containing a given string? Thanks for your help Andrzej Popielewicz <vasco@icpnet.pl> wrote: > "e.group" wrote: > > > Hi all, > > how can I find file/s (within a path), containing a given string? > > > > Thanks for your help > > man for find < path > -type f -print | xargs grep "a given string" /dev/null | cat -v Cypherpunk@nyc.rr.com wrote: > > Why do You reply to my answer. I did no ask. Did not You understand my answer ? Here is explanation : ...

Determine File Transfer Rate
Hi, I would like to conduct a test to compare the file transfer rates between 4 AIX servers, but not being familiar on how to do this. Could somebody enlighten me on how to accomplish these tests? thanks in advance I usually just pick a nice big file (500 mb or so) and time the FTP between them, just use the same file in each case. I am not sure if you were looking for something more advanced, but sometimes simple is all that is required. L8R, Jeff "Jay B" <jay08891@hotmail.com> wrote in message news:BJJyb.3624$yd.552602@news20.bellglobal.com... > Hi, > > I wo...

Close button bug
Hello, I have a form in an Access 2003 application which opens maximized. Its CloseButton property is set to false. On this form I have a command button that opens a report in preview mode. The report opens fine. It opens maximized as one would expect. However, the report preview window's close button is disabled which is confusing to my users (they have to click the resize button on the preview window which then restores the close button). Office SP3 does not seem to help. Is there a better workaround than this to restore my report preview close button? I can reproduce this behavi...