FAQ Database Discussion Community


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

java,caching,sync,flush,file-descriptor
Will this ensure that all data is synced on the local machine or just data originating within the currently operation JVM? FileOutputStream s = new FileOutputStream(filename) s.getFD().sync() FileInputStream fis = new FileInputStream(null); fis.getFD().sync(); Context: we have many programs (other software) that write to a file that we share. We all...

IO on file descriptors

c++,linux,file,ifstream,file-descriptor
I just ran into the following behavior and would like to know the reasons behind it: Assume a simplified program like that ... { std::ifstream in(argv[1]); assert(in.good()); while (std::getline(in, line)) { // Area 1 } in.close(); } { std::ifstream in(argv[1]); assert(in.good()); while (std::getline(in, line)) { // Area 2 } in.close();...

PHP / MYSQL connection failures under heavy load through mysql.sock

php,mysql,mariadb,file-descriptor
I've done quite a bit of reading before asking this, so let me preface by saying I am not running out of connections, or memory, or cpu, and from what I can tell, I am not running out of file descriptors either. Here's what PHP throws at me when MySQL...

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

c,linux,file-descriptor
Suppose that I have file name or an open file decriptor for a text file that resides on a storage device (hard disk, usb flash, dvd, etc.). How can I get block size of that device from file name/descriptor in Linux programmatically in C. I know about ioctl system call,...

Is hard limit of file descriptor changed in ruby 2.2?

ruby,unix,file-descriptor
I use p Process.getrlimit(:NOFILE) to get limit of file descriptor in my machine, I get [1024, 4096] shouldn't the hard limit be Process::RLIMI_INFINITY if I don't change the limit(accroding to book Working with unix process)? I use ruby 2.2...

Bash descriptors in sub shell

bash,file-descriptor
The snippet below was intended to listen and select a few songs from a directory: exec 3<&1 find /some/directory -name '*.mp3' -print0 | xargs -0 bash -c ' for i; do mplayer -ss 10 "$i" 1<&3 read -p "Select? (y/n)" -n 1 choice 1<&3 if [ "$choice" = "y" -o...

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
I am trying to obtain the output of a full-screen terminal program that uses redrawing escape codes to present data, and which requires a tty (or pty) to run. The basic procedure a human would follow is: Start the program in a terminal. The program uses redrawing to display and...

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

linux,qt,file-descriptor,filehandle,qtserialport
When a Qt app using QSerialPort experiences a non-clean shutdown (e.g. due to receiving and not handling SIGINT), how is the file descriptor of the serial port affected? After running an app that opens a QSerialPort on /dev/ttyS0, then quitting with Ctl-C, I am finding that cat < /dev/ttyS0 returns...

Tail command - follow by name on Solaris

filenames,solaris,file-descriptor,tail
Is there a way to tail a file by name on Solaris 10? Equivalent to: tail --follow=name Manual for tail on solaris shows no such option. Only -f is included and it looks like it follows a file by descriptor....

Who stole my file descriptors?

c,file-descriptor
I'm learning a socketpair() function. File descriptors returned by that function are 5 and 6. How can I check what files/sockets descriptors 3 and 4 were assigned to?

bad file descriptor from fread

c,file,io,file-descriptor,file-pointer
I try to use read() to get some characters from file just for learning this API. I have create a file called "file" in the same directory and it contains 1000 characters. But I got an error saying: read: %m: Bad file descriptor Here is the code: #include <stdio.h> #include...

How could I simulate a lack of file descriptor?

c,linux,file-descriptor
I would like to provoke a situation where there is no file descriptor remaining. I have been thinking about 2 possibilities: Opening thousands of files randomly until the result of open is -1 Set a very low number of file descriptor available (let's say stdin, stdout and stderr). How would...

Bash scripting: permanent pipe

linux,bash,scripting,pipe,file-descriptor
Here is a script I tried to write: #!/bin/bash cat <&3 & # runs in background, takes input from file desc 3 echo "To Terminal" ... echo "To cat" 1>&3 echo "to cat again" 1>&3 Essentially I want my script to spawn a program (in this case, cat) and be...

Garbage Collection invalidates FileDescriptor?

android,garbage-collection,file-descriptor
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) {...

Effect of closing descriptor for pipe

pipe,posix,file-descriptor
I have this piece of code which does the same work as ls -l | wc -l. main () { int i; int p[2]; pid_t ret; pipe (p); ret = fork (); if (ret == 0) { close (1); dup (p[1]); close (p[0]); execlp ("ls", "ls", "-l", (char *) 0);...

Same file descriptor after fork()

fork,file-descriptor,contention
I'm trying to understand what means duplicating a file descriptor after calling fork() and its possible effects on contention. In "The Linux Programming Interface" 24.2.1 (p517): When a fork() is performed, the child receives duplicates of all of the parent's file descriptors. These duplicates are made in the manner of...

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

linux,bash,file-descriptor,lsof
I did the following actions on two separate terminals: 1s term: Start process that is writing to file in background: └──> while true; do date >> log; sleep 1; done & [1] 20604 Get the PID of last process that is running in background: └──> echo $! 20604 2nd term:...