<div class="gmail_quote">On Fri, Aug 14, 2009 at 4:46 PM,  <span dir="ltr"><<a href="mailto:salsaman@xs4all.nl">salsaman@xs4all.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5"><br>
<br>
</div></div>/proc/$pid/fdinfo/$fd has a field called pos:<br>
<br>
if you grep for this maybe it will return what you are looking for.<br></blockquote></div><br>If fdinfo is unavailable on your kernel you can easily get this information by calling lseek() through gdb like this;<br><br>(contrived process that slowly reads from /etc/passwd)<br>
<br># while true; do read line; sleep 100; done < /etc/passwd<br>[3] 18255<br><br># ls -l /proc/18255/fd<br>total 0<br>lr-x------ 1 root root 64 Aug 14 17:07 0 -> /etc/passwd<br>lrwx------ 1 root root 64 Aug 14 17:07 1 -> /dev/pts/0<br>
lrwx------ 1 root root 64 Aug 14 17:07 2 -> /dev/pts/0<br>lrwx------ 1 root root 64 Aug 14 17:07 255 -> /dev/pts/0<br><br>notice that /etc/passwd is fd = 0 (obviously since I'm just redirecting it from the shell)<br>
<br># gdb -p 18255<br>GNU gdb Red Hat Linux (6.5-37.el5rh)<br>Copyright (C) 2006 Free Software Foundation, Inc.<br>GDB is free software, covered by the GNU General Public License, and you are<br>welcome to change it and/or distribute copies of it under certain conditions.<br>
Type "show copying" to see the conditions.<br>There is absolutely no warranty for GDB.  Type "show warranty" for details.<br>This GDB was configured as "x86_64-redhat-linux-gnu".<br>Attaching to process 18255<br>
Reading symbols from /bin/bash...(no debugging symbols found)...done.<br>Using host libthread_db library "/lib64/libthread_db.so.1".<br>Reading symbols from /lib64/libtermcap.so.2...(no debugging symbols found)...done.<br>
Loaded symbols for /lib64/libtermcap.so.2<br>Reading symbols from /lib64/libdl.so.2...<br>(no debugging symbols found)...done.<br>Loaded symbols for /lib64/libdl.so.2<br>Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.<br>
Loaded symbols for /lib64/libc.so.6<br>Reading symbols from /lib64/ld-linux-x86-64.so.2...<br>(no debugging symbols found)...done.<br>Loaded symbols for /lib64/ld-linux-x86-64.so.2<br>Reading symbols from /usr/lib64/gconv/ISO8859-1.so...(no debugging symbols found)...done.<br>
Loaded symbols for /usr/lib64/gconv/ISO8859-1.so<br><br>0x000000328ea97f15 in waitpid () from /lib64/libc.so.6<br>(gdb) call lseek(0, 0, 1)<br>$1 = 63<br>(gdb) detach<br>Detaching from program: /bin/bash, process 18255<br>
(gdb) quit<br><br>lseek parameters;<br><br>0 - stdin.. change this to whatever the fd you want to check is<br>0 - the amount to add to the offset - don't want to change it - just find out what it is<br>1 - SEEK_CUR - this means that offset is from the current position<br>
<br><br>Rob.<br>