file-descriptor

Increasing limit of FD_SETSIZE and select

巧了我就是萌 提交于 2019-11-26 22:09:23
I want to increase FD_SETSIZE macro value for my system. Is there any way to increase FD_SETSIZE so select will not fail Per the standards, there is no way to increase FD_SETSIZE . Some programs and libraries (libevent comes to mind) try to work around this by allocating additional space for the fd_set object and passing values larger than FD_SETSIZE to the FD_* macros, but this is a very bad idea since robust implementations may perform bounds-checking on the argument and abort if it's out of range. I have an alternate solution that should always work (even though it's not required to by the

Too many open files in python

浪子不回头ぞ 提交于 2019-11-26 20:55:18
问题 I wrote kind of a test suite which is heavily file intensive. After some time (2h) I get an IOError: [Errno 24] Too many open files: '/tmp/tmpxsqYPm' . I double checked all file handles whether I close them again. But the error still exists. I tried to figure out the number of allowed file descriptors using resource.RLIMIT_NOFILE and the number of currently opened file desciptors: def get_open_fds(): fds = [] for fd in range(3,resource.RLIMIT_NOFILE): try: flags = fcntl.fcntl(fd, fcntl.F

What can lead to “IOError: [Errno 9] Bad file descriptor” during os.system()?

隐身守侯 提交于 2019-11-26 20:23:02
问题 I am using a scientific software including a Python script that is calling os.system() which is used to run another scientific program. While the subprocess is running, Python at some point prints the following: close failed in file object destructor: IOError: [Errno 9] Bad file descriptor I believe that this message is printed at the same time as os.system() returns. My questions now are: Which conditions can lead to this type of IOError? What does it exactly mean? What does it mean for the

Exception when calling setDataSource(FileDescriptor) method (failed.: status=0x80000000)

核能气质少年 提交于 2019-11-26 20:20:22
问题 I'm developing a video streaming application and I'm getting stuck when calling set setDataSource with a FileDescriptor. I want my application to play the video as it is being downloaded, so once I get a minimum number of bytes, I move those bytes to another file so it can be played in another file while it's being downloaded in the original file. So, I check if I can start the media palyer every packet like this: if (mediaPlayer == null) { // Only create the MediaPlayer once we have the

How to write data to existing process's STDIN from external process?

别来无恙 提交于 2019-11-26 17:42:50
问题 I'm seeking for ways to write data to the existing process's STDIN from external processes, and found similar question How do you stream data into the STDIN of a program from different local/remote processes in Python? in stackoverlow. In that thread, @Michael says that we can get file descriptors of existing process in path like below, and permitted to write data into them on Linux. /proc/$PID/fd/ So, I've created a simple script listed below to test writing data to the script's STDIN (and

What's the difference between a file descriptor and file pointer?

霸气de小男生 提交于 2019-11-26 16:52:56
I want to know the difference between a file descriptor and file pointer. Also, in what scenario would you use one instead of the other? A file descriptor is a low-level integer "handle" used to identify an opened file (or socket, or whatever) at the kernel level, in Linux and other Unix-like systems. You pass "naked" file descriptors to actual Unix calls, such as read() , write() and so on. A FILE pointer is a C standard library-level construct, used to represent a file. The FILE wraps the file descriptor, and adds buffering and other features to make I/O easier. You pass FILE pointers to

Portable way to pass file descriptor between different processes

亡梦爱人 提交于 2019-11-26 15:24:59
On most UNIX systems passing an open file between processes can be easily done for child/parent processes by fork(); however I need to share a fd "after" the child was already forked. I've found some webpages telling me that sendmsg() may work for arbitary processes; but that seems very OS dependent and complex. The portlisten seems like the best example I can find, but I'd prefer a good wrapper library like libevent that hides all the magic of kqueue, pool, .... Does anyone know if there's some library (and portable way) to do this? Curt J. Sampson Your best bet is to try sending the file

Can anyone explain a simple description regarding 'file descriptor' after fork()?

我与影子孤独终老i 提交于 2019-11-26 12:07:05
问题 In \"Advanced Programming in the Unix Environment\", 2nd edition, By W. Richard Stevens. Section 8.3 fork function. Here\'s the description: It is important that the parent and the child share the same file offset. Consider a process that forks a child, then waits for the child to complete. Assume that both processes write to standard output as part of their normal processing. If the parent has its standard output redirected (by a shell, perhaps) it is essential that the parent\'s file offset

node and Error: EMFILE, too many open files

╄→гoц情女王★ 提交于 2019-11-26 11:46:49
问题 For some days I have searched for a working solution to an error Error: EMFILE, too many open files It seems that many people have the same problem. The usual answer involves increasing the number of file descriptors. So, I\'ve tried this: sysctl -w kern.maxfiles=20480 , The default value is 10240. This is a little strange in my eyes, because the number of files I\'m handling in the directory is under 10240. Even stranger, I still receive the same error after I\'ve increased the number of

How do file descriptors work?

删除回忆录丶 提交于 2019-11-26 10:10:25
问题 Can someone tell me why this does not work? I\'m playing around with file descriptors, but feel a little lost. #!/bin/bash echo \"This\" echo \"is\" >&2 echo \"a\" >&3 echo \"test.\" >&4 The first three lines run fine, but the last two error out. Why? 回答1: File descriptors 0, 1 and 2 are for stdin, stdout and stderr respectively. File descriptors 3, 4, .. 9 are for additional files. In order to use them, you need to open them first. For example: exec 3<> /tmp/foo #open fd 3. echo "test" >&3