file-descriptor

Changing offset from child processes

喜夏-厌秋 提交于 2019-12-12 04:31:39
问题 Let say that I have a parent process, and then create some number of child processes in order to read from the same file. when each process read from the file descriptor, is the offset been changed between all his sibling's processes? and so, is it possible that each process will read a unique line, or that without synchronized the app , each process will read the same lines like his siblings? id = fork(); if (id < 0) exit(EXIT_FAILURE); if (pipe(fd) == -1) exit(EXIT_FAILURE); switch (id) {

How to properly error trap read in c to get byte number from a file descriptor

若如初见. 提交于 2019-12-12 03:57:17
问题 I am currently writing a small dummy program to try and get the hang of properly using the read in c. I made a small function called readdata to read from the file descriptor and store in a buffer then return the number of bytes read. My problem is I am trying to correctly error handle and trap things so that there is no buffer overflow but I keep doing something from. Here is the tester: #include <stdio.h> #include <string.h> #include <unistd.h> #define BUFSIZE 10 int readdata(int fd, char

Garbage Collection invalidates FileDescriptor?

a 夏天 提交于 2019-12-11 20:33:47
问题 I'm opening an asset using a FileDescriptor on Android. It appears that garbage collection changes the FileDescriptor's internal descriptor to -1. Attempting to use the FileDescriptor after that throws an exception. As a sanity check, I added this code to a blank project: try{ fd = getAssets().openFd("greensleeves.wav").getFileDescriptor(); }catch(IOException e) { } System.out.println("file descriptor before gc" + fd); try { Thread.sleep(100); } catch (InterruptedException e) {} System.out

Writing to two file descriptors by only one operation

拜拜、爱过 提交于 2019-12-11 18:34:25
问题 I want to implement logging functionality in C and log messages to both stdout and some file. I would like to write something like fprintf(logout, "msg"); with somehow declared FILE* logout which will redirect strings to both stdout and some file. Is it possible? 回答1: You apparently want a FILE -like object that redirects its writes to two underlying FILE s ( stdout and the log file). Standard C doesn't allow "subclassing" FILE objects in any way, so this is not possible in C. However, GNU

File pointers after returning from a forked child process

眉间皱痕 提交于 2019-12-11 18:26:06
问题 Is it normal, for a given file descriptor shared between a forked parent and child process, that the file position in the parent process remains the same after a child process reads from the same file descriptor? This is happening for me. Here's the setup: I am writing a C++ CGI program, so it reads http requests from stdin. When processing a multipart_form, I process stdin with an intermediary object (Multipart_Pull) that has a getc() method that detects the boundary strings and returns EOF

Switching between statements if the user inputs something: infinitely and with a timeout [duplicate]

那年仲夏 提交于 2019-12-11 14:13:28
问题 This question already has answers here : Is it necessary to reset the fd_set between select system call? (2 answers) Closed 4 years ago . To explain more clearly what I want to do, I want my code to check if the user inputs something (or if another file descriptor than 0 has data to read) every (let's say) 2.5 seconds and so until the program stops. If the user inputs something, a simple printf() will notify him and then the program will check again if the user inputs something in the next 2

linux pipe data from file descriptor into a fifo

人走茶凉 提交于 2019-12-11 13:38:02
问题 Lets say I know that a file descriptor fd is open for reading in my process. I would like to pipe data from this fd into a fifo that is available for reading outside my of process, in a way that avoids calling poll or select on fd and manually reading/forwarding data. Can this be done? 回答1: You mean ask the OS to do that behind the scenes on an ongoing basis from now on? Like an I/O redirection? No, you can't do that. You could spawn a thread that does nothing but read the file fd and write

How to do a non-blocking read on a non-socket fd

隐身守侯 提交于 2019-12-11 12:05:29
问题 Is there a way to do a single read() in non-blocking mode on a pipe/terminal/etc, the way I can do it on a socket with recv(MSG_DONTWAIT) ? The reason I need that is because I cannot find any guarantee that a read() on a file-descriptor returned as ready for reading by select() or poll() will not block. I know can make the file descriptor non-blocking with fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) but this will change the mode on that file descriptor globally, not just in the

Locating file descriptor leak in OS X application

旧城冷巷雨未停 提交于 2019-12-11 06:06:48
问题 Background I have some very complex application. It is composition of couple libraries. Now QA team found the some problem (something reports an error). Fromm logs I can see that application is leaking a file descriptors (+1000 after 7 hours of automated tests). QA team has delivered rapport "opened files and ports" from "Activity monitor" and I know exactly to which server connection is not closed. From full application logs I can see that leak is quite systematic (there is no sudden burst),

The read method on the inotify descriptor does not return

一笑奈何 提交于 2019-12-11 04:23:51
问题 My program monitors changes on files using inotify(7) fd = inotify_init(); inotify_add_watch (fd, "./test.txt", IN_ALL_EVENTS); //start forever monitor while(true){ ssize_t len, i = 0; char action[81+FILENAME_MAX] = {0}; char buff[BUFF_SIZE] = {0}; len = read (fd, buff, BUFF_SIZE); while (i < len) { //process event i += sizeof(struct inotify_event) + pevent->len; } } The problem is that the read function only return several times for the firt changes in the monitor file (ACCESS, OPEN, MODIFY