The kernel maintains a per-process table of file descriptors. Otherwise a multi-user multi-process system could not even work, as the STDIN, STDOUT and STDERR file descriptors (0, 1, 2) of all processes would have to point to the same file (terminal), but they are obviously using independent terminals. On the...
c,file,io,file-descriptor,file-pointer
Your read_indent function takes a file descriptor, but you're passing in a FILE* pointer. Try turning the FILE* pointer into a file descriptor using fileno: int a = read_indent(fileno(file_pt)); ...
On Linux 3.0 or newer the default hard ulimit is 4096. See this commit. The author of the book probably used some other Unix-like operating system where it's indeed Process::RLIM_INFINITY.
linux,bash,scripting,pipe,file-descriptor
Try: #!/bin/bash exec 3> >(cat) echo "To Terminal" echo "To cat" 1>&3 echo "To cat again" 1>&3 exec 3>&- cat, of course, does nothing interesting. For an example that is still simple but slightly more interesting output, replace cat with awk: exec 3> >(awk '{print NR,length($0),$0}') ...
Use /dev/stdout or /dev/fd/1. ./program /dev/stdout ...
c,websocket,file-descriptor,libwebsockets
You are trying to push water up hill. Caveat: I've only written a server that does this, not a client; however, the interface is very similar Firstly, libwebsockets is written on the basis you will use poll or ppoll rather than select. I'm sure it's possible to use select, but...
php,mysql,mariadb,file-descriptor
Most likely it is due to net.core.somaxconn What is the value of /proc/sys/net/core/somaxconn net.core.somaxconn # The maximum number of "backlogged sockets". Default is 128. Connections in the queue which are not yet connected. Any thing above that queue will be rejected. I suspect this in your case. Try increasing it...
c,sockets,server,file-descriptor
Check the return value of the recv(). If the user terminated abnormally then return value should be zero 0. Based on that you can close fd easily. if(recv(fd,buffer,length,flag) == 0) close(fd); ...
c,file,sockets,redirect,file-descriptor
I don't know about any efficient way to do this without a buffer, so here is an example without using separate threads and only one buffer. You could use the doRW function below from multiple threads, but only with one buffer per thread. Recv and send seem to be thread...
python,subprocess,file-descriptor,pty
If the program does not generate much output; the simplest way is to use pexpect.run() to get its output via pty: import pexpect # $ pip install pexpect output, status = pexpect.run('top', timeout=2, withexitstatus=1) You could detect whether the output is "settled down" by comparing it with the previous output:...
To improve on Frederik Deweerdt' answer (and assuming a Linux system), for debugging purposes you might add the following (for Linux systems) after a successful call to socketpair(2) (so after the check that it did not fail): char cmdbuf[64]; snprintf (cmdbuf, sizeof(cmdbuf), "/bin/ls -l /proc/%d/fd/", (int) getpid()); system(cmdbuf); but this...
java,caching,sync,flush,file-descriptor
Does FileDescriptor.sync() work for all file data No. or just file data originating within the callers JVM It works on the current file descriptor only, which is necessarily within the caller's JVM, along with the data he is writing....
c++,linux,file,ifstream,file-descriptor
The head process is executed once by bash and has it's output redirected to a pipe which your process can access through that file inode. Your program knows nothing about that head command and trying to close and re-open the file won't cause it to be executed again. It's similar...
As fstat() man page says: int fstat(int fildes, struct stat *buf); int stat(const char *path, struct stat *buf); The stat() function obtains information about the file pointed to by path. Read, write or execute permission of the named file is not required, but all directories listed in the path name...
No, I have not encountered a use case where this makes sense. The FileDescriptor documentation is pretty clear that while you can construct a FileDescriptor directly, you should not: Instances of the file descriptor class serve as an opaque handle to the underlying machine-specific structure representing an open file, an...
fork,file-descriptor,contention
When you see the phrase "duplicate a file descriptor", you need to understand it as "create a new file descriptor which points to the same thing the other one is pointing to". So when you duplicate fd 3, you get fd 4. The aren't the same number, but they identify...
wc stops when there isn't any more input. So even if the child finished writing to the pipe, the parent waits for more input from itself because p[1] on it's side isn't closed. So by closing p[1], the parent process expresses it's intent that isn't going to provide input to...
linux-kernel,handle,file-descriptor,dup,windows-nt
You should consider the following: file descriptor is merely an offset into the array of "file" (literally, that's what they are called) object pointers on the kernel side. So when you duplicate the file descriptor, the kernel will simply copy the value of the file pointer from one location in...
First i'm going to tell you how I kept the file descriptors from leaking (this is the solution I implemented). Then i'm going to tell you a way to force the file descriptors to be released. 1. I noticed in all my testing that when a sound file is...
Silly me! It's the FD 0 -- not 1 -- that should be redirected. A version that works as intended below: exec 3<&0 find /media/jeenu/USB/ -type f -print0 | xargs -0 bash -c ' for i; do mplayer -ss 10 "$i" read -p "Select? (y/n/q)" -n 1 choice case "$choice"...
filenames,solaris,file-descriptor,tail
According to the GNU tail manual, --follows is the same as -f: -f, --follow[={name|descriptor}] output appended data as the file grows; an absent option argument means 'descriptor' A -f option is found in the POSIX description of tail. However, the --follows option (which accepts an option value) is not in...
linux,qt,file-descriptor,filehandle,qtserialport
Under POSIX, terminal devices (that is, serial ports and pseudoterminals) have a whole bunch of settings which enable the computer to speak the multitude of variations on the basic RS-232 protocol that exist or have existed. A great deal of this API was designed back in the days when dinosaurs...
linux,shell,unix,file-descriptor,io-redirection
If you want a byte written to one file descriptor (pipe, socket etc.) to show up as readable data on more than one file descriptor which are not dup()s of each other (but e.g. they correspond to two different regular files), then it's not possible on a generic Unix system....
c,unix,fork,file-descriptor,close
Yes. Each process has a copy of the file descriptor (among other things). So one process closing it won't affect the copy of the fd in other process. From fork() manual: The child inherits copies of the parent's set of open file descriptors. Each file descriptor in the child refers...
This is probably because of the \r\n characters in your file, which stand for newline on Windows systems. On my machine (Mac OS X 10.10) your code gives the right result for your file, provided it doesn't have any newline character on the end, i.e. only the string: ABCDABCDDABCDABCD (output...
ruby,linux,process,exec,file-descriptor
This certainly isn't the solution I was looking for, but in the absence of any revelations about the :close_options Hash and Process.spawn or Process.exec, I wound up manually adding all the file descriptors I cared about to the options array, which did the trick: server_fd = self.server.to_i client_fds = self.clients.map...
c,linux,sockets,file-descriptor
Stevens (et al) UNIX® Network Programming, Vol 1: The Sockets Networking API describes the process of transferring file descriptors between processes in Chapter 15 Unix Domain Protocols and specifically §15.7 Passing Descriptors. It's fiddly to describe in full, but it must be done on a Unix domain socket (AF_UNIX or...
perl,email,smtp,send,file-descriptor
MIME::Lite SMTP debugging procedure Try to narrow search for your problem. 1: Do you get SMTP greeting message when you telnet the SMTP host? telnet mail.domain.net 25 1:YES => add debug option to MIME::Lite send (via SMTP) call. $msg->send("smtp", "mail.domain.net", Debug=>1, AuthUser=>'[email protected]', AuthPass=>"password" ); ...
This is solved by using io.open() instead of os.fdopen() Note that you must use buffering=0 for this to work: rf = io.open(r, 'rb', 0) rf.read(10) ...
linux,bash,file-descriptor,lsof
You have a classic engineering problem in the form of asynchronous sampling here. Essentially, every long period of waiting time, a process will be very quickly spun up, write to a file, and then die. Entirely asynchronous to that, you run lsof which looks for open files - but only...
04000 (with the leading zero) is an octal integer literal, and 2 (decimal) = 2 (octal) = O_RDWR 2050 (decimal) = 4002 (octal) = O_RDWR | O_NONBLOCK which means that setting the O_NONBLOCK flag just worked fine. For easier comparison with the O_XXX definitions you could print the flags as...
android,garbage-collection,file-descriptor
You aren't retaining a reference to the AssetFileDescriptor created by openFd(). When it gets GC'ed, it has an internal ParcelFileDescriptor that is also eventually GC'ed. That, in turn, has the reference to the FileDescriptor that you are retrieving in the call to getFileDescriptor(). It also happens to have a finalize()...
c,buffer,system,file-descriptor
The read() has the below prototype: int read( int handle, void *buffer, int nbyte ); It returns number of bytes successfully read . 0 when EOF is reached.-1 when there is an error. Yes nlbajt = 0 means EOF here. ...
python,cgi,stdin,file-descriptor,sys
I don't know for sure, but I would bet that os.close() is just a python wrapper for the OS's close() system call. Python file objects handle some cool stuff for the user like internal buffering of data and whatnot and this is taken care of when calling its close() method....
read() uses the file descriptor, not the file name: readResult = read(frameFD , buff, BUFFER_SIZE);...
You can limit the number of file descriptors a process can open under Linux using ulimit. Executing ulimit -n 3 before running your C program should make it an error to open any more files, since stdin, stdout, and stderr take up the first 3 descriptors. An example: $ ulimit...