file-descriptor

Determining whether a readable file descriptor is the read end of a pipe

I would like to use splice to zero-copy data from STDIN_FILENO to a file descriptor (which could be to a regular file, char or block device, FIFO, or anything that can be opened with open). In order to use splice, either the from file descriptor or to file descriptor must be the appropriate end of a pipe, so generally a pipe is created t...

How to prevent stdin stream from reading data from associated file descriptor on program start?

I'm using select() call to detect input presence in the main cycle of my program. This makes me use raw file descriptor (0) instead of stdin. While working in this mode I've noticed that my software occasionally loses a chunk of input at the beginning. I suspect that stdin consumes some of it on the program start. Is there a way to prev...

How can DIR* get EBADF error?

I have some code that I have inherited which is part of a class for iterating, accessing the directory content and uses boost::filesystem::path. The code reads in part: struct directory_iterator_impl { private: void skip_dots(const path& p, const char* who) { static const std::string d("."); static const std::string dd(".."...

Using file descriptors to communicate between processes

I have the following python code: import pty import subprocess os=subprocess.os from subprocess import PIPE import time import resource pipe=subprocess.Popen(["cat"], stdin=PIPE, stdout=PIPE, stderr=PIPE, \ close_fds=True) skip=[f.fileno() for f in (pipe.stdin, pipe.stdout, pipe.stderr)] pid, child_fd = pty.fork()...

File descriptor of a java datagram socket

Hi, How do I get the file descriptor of a Java Datagram socket? I've searched the web without any success. Srini ...

Why does open make my file descriptor 0?

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 outputfd = open("file", O_RDWR | O_CREAT | O_TRUNC) == -1 Can someone let me know wh...

is the file pointed by stdin file descriptor the same file for different processes?

I have a question in mind. By convention, unix associates the file descriptor 0, 1, 2 for stdin, stdout, stderr on every process. Is the file, e.g. pointed by stdin, shared by different processes? If shared, when we open two shells to type some inputs to these two shells, how is the os doing to manage the shared file? ...

Manipulate File Descriptors for select.select in Python

Hello everyone, I have an itching problem I know could be solved using many different ways, but I would still like to know if the following approach is possible in Python. Suppose I have some socket I am constantly waiting for input on, and there is some condition that eventually terminates the whole program. I want to do it in a BLOCK...

What is bad file descriptor in c?

This is my code of function that wants to read file: int sendByByte(int filed,int sockfd,int filesize) { int i=0; int sent=0; char buf[BUFSIZE]; while(i<filesize) { printf("fd is : %d\n",filed); printf("i: %d\n",i); int byte_read=read(filed,buf,BUFSIZE); if(byte_read == -1) { printf("MOSHKEL dar read\n"); return -1;...

How does linux file descriptor limits work?

I was told that my server refused to accept client network connections at a specific port could be due to the lack of file descriptors. I looked up what this is all about and read about it here: http://www.netadmintools.com/art295.html So I tested my system and I got this: cat /proc/sys/fs/file-nr 1088 0 331287 What does this m...