file-descriptor

File Descriptor Assignment in C

When sockets are created or files are opened/created in C, is the file descriptor that's assigned to the socket/file guaranteed to be the lowest-valued descriptor available? What does the C spec say about file descriptor assignment in this regard, if anything? ...

Closing/cleaning up "mixed" file descriptors / sockets.

When I create a socket using accept() and make a FILE out of it using fdopen(), what do I have to do to clean everything up? Do I need to do fclose() on the FILE, shutdown() and close() on the socket, or only the shutdown() and or close() or fclose()? If I don't do fclose(), do I have to free() the FILE pointer manually? ...

Is there a need to close file descriptors before exit?

Of course, the immediate answer for most situations is "yes", and I am a firm believer that a process should correctly cleanup any resources it has allocated, but what I have in my situation is a long-running system daemon that opens a fixed number of file descriptors at the startup, and closes them all before exiting. This is an embedd...

How to close a file descriptor from another process in unix systems

You can use command lsof to get file descriptors for all running processes, but what I would like to do is to close some of those descriptors without being inside that process. This can be done on Windows, so you can easily unblock some application. Is there any command or function for that? ...

Is there a file descriptor leak when using sockets on a linux platform?

If I open and close a socket by calling for instance Socket s = new Socket( ... ); s.setReuseAddress(true); in = s.getInputStream(); ... in.close(); s.close(); Linux states that this socket is still open or at least the file descriptor for the connection is presen. When querying the open files for this process by lsof, there is an en...

How to create a customized file descriptor on linux

I would like to create a file whose descriptor would have some customizable behavior. In particular, I'd like to create a file descriptor, which, when written to, would prefix every line, with name of the process and pid (and maybe time), but I can imagine it can be useful to do other things. I don't want to alter the writing program - ...

Windows equivalent of ulimit -n

Hi, What is the windows equivalent of the unix command " ulimit -n" ? Basically, i want to set the maximum fd limit via command prompt. ...

Getting the highest allocated file descriptor

Is there a portable way (POSIX) to get the highest allocated file descriptor number for the current process? I know that there's a nice way to get the number on AIX, for example, but I'm looking for a portable method. The reason I'm asking is that I want to close all open file descriptors. My program is a server which runs as root and...

Are there any standard input/ouput macros for read/write system calls in C?

All my searches returned nothing and I find it odd that there aren't any macros to use as file descriptors for read/write system calls for standard input and output instead of a 0 (stdout) and a 1 (stdin). Am I missing them or they really don't exist? ...

Netbeans problem: Can't add application descriptor, getting null pointer exceptions

When I try to add to the application descriptor in a Netbeans mobile project by clicking on 'Add' in the 'Application Descriptor' panel in the projecct config window nothing happens, netbeans gives a red button on the bottom right indicating an error, clicking on that reveals this: java.lang.NullPointerException at org.netbeans.modu...

N:1 file descriptors???

Is it possible to have N file descriptors be seen to a program as 1 file descriptor such that data received on any of the N file descriptors (ie from N sockets) will be forwarded back to the calling API on the single file descriptor, hiding the fact that it may actually be coming from a different file descriptor? Is it also possible to h...

Sockets & File Descriptor Reuse (or lack thereof)

Hi, I am getting the error "Too many open files" after the call to socket in the server code below. This code is called repeatedly, and it only occurs just after server_SD gets the value 1022. so i am assuming that i am hitting the limit of 1024 as proscribed by "ulimit -n". What i don't understand is that i am closing the Socket, whic...

Unix: seeing file handles like with "lsof -l"

I did the commands (source): $ exec 3>/tmp/thirdfile $ exec 4>/tmp/fourthfile $ echo drib >&3 $ echo drab >&4 $ echo another drib >&3 $ echo another drab >&4 $ exec 3>&- $ exec 4>&- How can I see the file handles, something like with "lsof -l"? ...

Check the open FD limit for a given process in Linux

Hi, I recently had a Linux process which "leaked" file descriptors: It opened them and didn't properly close some of them. If I had monitored this, I could tell - in advance - that the process was reaching its limit. Is there a nice, Bash\Python way to check the FD usage ratio for a given process in a Ubuntu Linux system? EDIT: I no...

socket: Too many open files (24) apache bench lighttpd

When I start Apache Bench test: ab -n 10000 -c 1300 http://domain.com/test.php I get error: socket: Too many open files (24) When i change to '-c 1000' it works fine. Because I can have more than 1000 concurrent users I would like to fix socket too many open files problem or increase parameter. How to do this and where? I u...

How to read exactly one line?

I have a Linux file descriptor (from socket), and I want to read one line. How to do it in C++? ...

Duplicate file descriptor with its own file offset

How can one create a new file descriptor from an existing file descriptor such that the new descriptor does not share the same internal file structure/entry in the file table? Specifically attributes such as file offset (and preferably permissions, sharing and modes) should not be shared between the new and old file descriptors. Under b...

Empty or "flush" a file descriptor without read()?

(Note: This is not a question of how to flush a write(). This is the other end of it, so to speak.) Is it possible to empty a file descriptor that has data to be read in it without having to read() it? You might not be interested in the data, and reading it all would therefore waste space and cycles you might have better uses for. If ...

IOException: Too many open files

I'm trying to debug a file descriptor leak in a Java webapp running in Jetty 7.0.1 on Linux. The app had been happily running for a month or so when requests started to fail due to too many open files, and Jetty had to be restarted. java.io.IOException: Cannot run program [external program]: java.io.IOException: error=24, Too many open...

How do Perl file descriptors work on Windows?

Are file descriptors supported on windows? Why do things "seem to work" in Perl with fds? Things like "fileno", "dup" and "dup2" were working but then randomly inside some other environment, stopped working. It's hard to give details, mostly what I'm looking for is answers from experienced Windows programmers and how file descriptors ...