file-descriptor

fopen problem - too many open files

廉价感情. 提交于 2019-12-23 12:28:57
问题 I have a multithreaded application running on Win XP. At a certain stage one of a threads is failing to open an existing file using fopen function. _get_errno function returns EMFILE which means Too many open files. No more file descriptors are available . FOPEN_MAX for my platform is 20. _getmaxstdio returns 512. I checked this with WinDbg and I see that about 100 files are open: 788 Handles Type Count Event 201 Section 12 File 101 Port 3 Directory 3 Mutant 32 WindowStation 2 Semaphore 351

Preventing lock propagation

南楼画角 提交于 2019-12-23 07:48:58
问题 A simple and seemingly reliable way to do locking under bash is: exec 9>>lockfile flock 9 However, bash notoriously propagates such a fd lock to all forked stuff including executed programs etc. Is there any way to tell bash not to duplicate the fd? It's great that the lock is attached to a fd which gets removed when the program terminates, no matter how it gets terminated. I know I can do stuff like: run_some_prog 9>&- But that is quite tedious. Is there any better solution? 回答1: You can use

Is creating two FILEs for the same file descriptor well-defined?

旧巷老猫 提交于 2019-12-23 07:11:40
问题 POSIX specifies an fdopen function that creates a FILE for a file descriptor. POSIX also specifies a fileno function that returns the file descriptor for a FILE . Together, these two could be used to create a second FILE accessing the same underlying file descriptor as an existing file: FILE *secondfile(FILE *f, const char *mode) { int fd = fileno(f); return fd >= 0 ? fdopen(fd, mode) : NULL; } Is this a well-defined operation under POSIX? What happens when I access both the original FILE and

How to run a command using pipe?

故事扮演 提交于 2019-12-22 11:14:14
问题 I am trying to run ls|wc using execvp. So I create a pipe and then fork to create a child. I close the appropriate(read./write) end in parent/child and then map the other end to stdout/stdin. Then I run the ls in parent using execvp and wc in child. When I run the program it says wc:standard input:bad file descriptor. 0 0 0 wc: -:Bad file descriptor Here is my code: int main() { //int nbBytes = 0; //stream length int pfd_1[2]; //file descriptor //char buffer[MAX_FILE_LENGTH]; char* arg[MAX

Use multiple output stream in python?

▼魔方 西西 提交于 2019-12-22 10:53:03
问题 What I am going to do is to create multiple output steams in a python function, and refer them as 1 , 2 , 3 .....: In test.py : def main(): ... print >>fd1, 'words1' print >>fd2, 'words2' print >>fd3, 'words3' ... Redirect it while using: python test.py 1>1.txt 2>2.txt 3>3.txt The content of these files: 1.txt -> words1 2.txt -> words2 3.txt -> words3 The question is, how to create those fd1 , fd2 , fd3 ? Added: I have used this: outfiles = {} for _ in range(3): fd = os.dup(1) outfiles[fd] =

Bash double process substitution gives bad file descriptor

眉间皱痕 提交于 2019-12-22 04:24:44
问题 When I try to refer to two process substitution pipes in a bash function, only the first one referenced works. The second one gives a "bad file descriptor" error like so: $ foo(){ > cat "$1" > cat "$2" > } $ foo <(echo hi) <(echo bye) hi cat: /dev/fd/62: Bad file descriptor $ It appears that the second pipe is dropped once one is referenced, but a) I cannot seem to confirm this behavior in any documentation and b) I wish it wouldn't. =) Any ideas on what I'm doing wrong? FWIW I'm doing this

What are the possible values for file descriptors?

浪子不回头ぞ 提交于 2019-12-22 03:49:32
问题 I am interested to know the valid values which I can expect for a file descriptor. Please let me explain a bit. I know that, for instance, when I use #include <unistd.h> on my linux system then a call to open a file for reading: int fileDescriptor; fileDescriptor = open("/some/filename",O_RDONLY); an error might occur and I receive -1 as a result. Incidently the (-1) negative one must have somewhat of a special meaning. Is it that all other values are valid file descriptors? i.e. also

Is HANDLE similar to file descriptor in Linux?

被刻印的时光 ゝ 提交于 2019-12-22 03:16:08
问题 Is HANDLE similar to file descriptor in Linux? As far as I know, HANDLE is used for handling every resources on Windows, such as font, icons, files, devices..., which in essence is just a void pointer point to a memory block holding data of a specific resource 回答1: Yes, Windows handles are very similar to Unix file descriptors (FDs). Note that a HANDLE is not a pointer to a block of memory. Although HANDLE is typedef 'd as void * , that's just to make it more opaque. In practice, a HANDLE is

Is HANDLE similar to file descriptor in Linux?

孤街浪徒 提交于 2019-12-22 03:16:05
问题 Is HANDLE similar to file descriptor in Linux? As far as I know, HANDLE is used for handling every resources on Windows, such as font, icons, files, devices..., which in essence is just a void pointer point to a memory block holding data of a specific resource 回答1: Yes, Windows handles are very similar to Unix file descriptors (FDs). Note that a HANDLE is not a pointer to a block of memory. Although HANDLE is typedef 'd as void * , that's just to make it more opaque. In practice, a HANDLE is

Can I close file descriptors for currently unused UIAppFonts?

强颜欢笑 提交于 2019-12-21 20:05:19
问题 We bundle a lot of fonts with our iOS app, and we put them all in UIAppFonts for faster loading. (We're using them inside UIWebView and it's much faster than using loading files with @font-face ). However this lead me to occasionally get this kind of warning: Mar 13 23:07:16 iPad afcd[2582] <Error>: Max open files: 78 Mar 13 23:07:17 iPad mobile_house_arrest[2584] <Error>: Max open files: 78 Mar 13 23:07:17 iPad mobile_house_arrest[2586] <Error>: Max open files: 78 Mar 13 23:07:17 iPad mobile