file-descriptor

C's printf and fprintf(stdout,) are not printing

江枫思渺然 提交于 2019-11-28 07:09:24
问题 This is a bit of an odd one. My code wasn't outputting what I thought it should. I added some print statements at various stages to see where it was going wrong. Still nothing. So I added a printf statement at the start of main. That's where I got really confused. So I presumed something funny was happening with the file descriptors. I changed the printf to a fprintf . Still nothing. Printing to stderr with fprintf does work! Why is this happening? Removing all of the body from main except

How to pass file descriptors from parent to child in python?

孤者浪人 提交于 2019-11-28 04:22:35
问题 I am using multiprocessing module, and using pools to start multiple workers. But the file descriptors which are opened at the parent process are closed in the worker processes. I want them to be open..! Is there any way to pass file descriptors to be shared across parent and children? 回答1: There isn't a way that I know of to share file descriptors between processes. If a way exists, it is most likely OS specific. My guess is that you need to share data on another level. 回答2: On Python 2 and

Read/write from file descriptor at offset

会有一股神秘感。 提交于 2019-11-28 03:14:27
问题 I've been using the read(2) and write(2) functions to read and write to a file given a file descriptor. Is there any function like this that allows you to put an offset into the file for read/write? 回答1: Yes, you're looking for lseek . http://linux.die.net/man/2/lseek 回答2: There are pread/pwrite functions that accept file offset: ssize_t pread(int fd, void *buf, size_t count, off_t offset); ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); 回答3: Yes. You use the lseek

Why does open make my file descriptor 0?

独自空忆成欢 提交于 2019-11-28 02:15:53
I'm working on a program that is using a pipe and forks and need to change the write end to an output file. But when I open a file the file descriptor is 0 which is usually stdin but which I think is the cause of some of my problems. Here is my code if (outputfd = open("file", O_RDWR | O_CREAT | O_TRUNC) == -1) { // open failed } Can someone let me know why it is 0? Or how to fix it? It's because you're comparing it to -1 . outputfd doesn't get the result of open . It gets the result of the check for -1 . doron outputfd in your line of code is not the output file descriptor but rather is equal

Why does poll keep returning although there is no input?

北城余情 提交于 2019-11-28 01:13:28
问题 I wrote a small test program to figure out how to talk to poll. I created three files testa , testb , testc and wrote the string hello\n to the first. So, here is my invocation of poll : poll(polls.data(),polls.size(),-1) According to the manpage, a timeout of -1 should indicate that the syscall never times out. However, it keeps returning without having anything to read. I always consume one byte of the input and can see the hello\n being printed, but poll doesn't stop there. It just keeps

Is O_LARGEFILE needed just to write a large file?

霸气de小男生 提交于 2019-11-27 23:02:05
Is the O_LARGEFILE flag needed if all that I want to do is write a large file ( O_WRONLY ) or append to a large file ( O_APPEND | O_WRONLY )? From a thread that I read titled " Cannot write >2gb index file " on the CLucene-dev mailing list, it appears that O_LARGEFILE might be needed to write large files, but participants in that discussion are using O_RDWR , not O_WRONLY , so I am not sure. O_LARGEFILE should never be used directly by applications. It's to be used internally by the 64-bit-offset-compatible version of open in libc when it makes the syscall to the kernel (Linux, or possibly

Too many open files in python

烈酒焚心 提交于 2019-11-27 21:56:32
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_GETFD) except IOError: continue fds.append(fd) return fds So if I run the following test: print get_open

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

时光总嘲笑我的痴心妄想 提交于 2019-11-27 20:59:09
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 subprocess that has been invoked by os.system() ? You get this error message if a Python file was

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

流过昼夜 提交于 2019-11-27 20:25:45
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 minimum // buffered data if (totalKbRead >= INTIAL_KB_BUFFER) { try { startMediaPlayer(); } catch

Why is select used in Linux

瘦欲@ 提交于 2019-11-27 20:16:26
问题 I was going through a serial program and I observed that they use select() before using read() . Why exactly is this required. Why cant we just directly call read() and check if it fails or not ? Also why do we have to increment the file descriptor by 1 and pass it while I am passing the file descriptor set already to select() ? Example: r=select(fd+1, &fds, NULL, NULL, &timeout); where fds already has the value of fd 回答1: The select() system call tells you whether there is any data to read