0

There is a method to seek with a filehandle in C,

int fseek(FILE *stream, long offset, int whence);

There is also a file in fdinfo for each file descriptor,

cat /proc/self/fdinfo/2
pos:    0
flags:  0100002
mnt_id: 24

What I want to do is call fseek on a file handle belonging to another process. Is this currently possible?

0

I am guessing "no", but feel to correct me.

Here I create a test file (/tmp/f), and a perl script that echos its pid, opens our test file and sleeps.

echo foobar > /tmp/f;
perl -E'$|=1; print $$; open my $fh, "<", "/tmp/f" or die $!; sleep while 1'

The pid outputted was 19992. Now here is what's going on in /proc/19992/fd,

$ cd /proc/19992/fd/
$ sudo cat 3
foobar

And in /proc/19992/fdinfo,

$ cat 3 
pos:    0
flags:  02100000
mnt_id: 27

$ sudo cat 3  > 3
bash: 3: Permission denied

$ sudo echo "pos=0"  > 3
bash: 3: Permission denied

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.