Menu
  • HOME
  • TAGS

Two different files but the same descriptor?

c,file-descriptor

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...

bad file descriptor from fread

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)); ...

Is hard limit of file descriptor changed in ruby 2.2?

ruby,unix,file-descriptor

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.

Bash scripting: permanent pipe

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}') ...

Make a C program write to standard output even though it requires a filename for its output

c,file-descriptor

Use /dev/stdout or /dev/fd/1. ./program /dev/stdout ...

libwebsockets for C, can i use websocket file descriptor with select()?

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 connection failures under heavy load through mysql.sock

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...

Client/server chatroom: Handle unexpected disconnect

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 socket redirection

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...

How do I obtain the output from a program that uses screen redrawing for use in a terminal screen scraper?

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:...

Who stole my file descriptors?

c,file-descriptor

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...

Does FileDescriptor.sync() work for all file data or just file data originating within the callers JVM

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....

IO on file descriptors

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...

Get storage device block size from name/descriptor of a file on that device

c,linux,file-descriptor

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...

Is there a use case for direct FileDescriptor instantiation? [duplicate]

java,file-descriptor

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...

Same file descriptor after fork()

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...

Effect of closing descriptor for pipe

pipe,posix,file-descriptor

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...

True file descriptor clone

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...

playSoundFileNamed is leaving the sound files open, using up file descriptors and causing a crash

ios,xcode,file-descriptor

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...

Bash descriptors in sub shell

bash,file-descriptor

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"...

Tail command - follow by name on Solaris

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...

QSerialPort effect on `/dev/ttyS*` after process end?

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...

Unix shell descriptor redirection

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....

File descriptors before fork()

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...

Lseek not working

c,file-descriptor,lseek

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...

How to mimic execl() in Ruby

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...

Sending file descriptor by Linux socket

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 MIME::Lite bad file descriptor

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" ); ...

Reading from unbuffered os.fdopen() file object doesn't behave like os.read()

python,file-descriptor

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) ...

Who is writing to my file or why lsof did not display the writer but reader do

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...

fcntl() and F_GETFL: strange result

c,sockets,file-descriptor

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...

Garbage Collection invalidates FileDescriptor?

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 read() and write() while loop

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. ...

Difference between os.close(0) & sys.stdin.close()

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....

Error while Reading from a file

c,file-io,file-descriptor

read() uses the file descriptor, not the file name: readResult = read(frameFD , buff, BUFFER_SIZE);...

How could I simulate a lack of file descriptor?

c,linux,file-descriptor

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...