Re: rm-ing files with open file descriptors

From: Ville Herva (vherva@niksula.hut.fi)
Date: Sat Jan 19 2002 - 06:15:11 EST


On Fri, Jan 18, 2002 at 06:29:36PM -0800, you [H. Peter Anvin] said:
>
> This *might* work:
>
> link("/proc/self/fd/40", newpath);

I don't think so: firstly, it would create a cross device link and secondly,
/proc/<pid>/fd/* are symbolic links. See:

/tmp>while true; do sleep 1; echo kukkanen; done > r &
[1] 19925
/tmp>L /proc/19925/fd
total 0
lrwx------ 1 root root 64 Jan 19 13:10 0 -> /dev/pts/7
l-wx------ 1 root root 64 Jan 19 13:10 1 -> /tmp/r
lrwx------ 1 root root 64 Jan 19 13:10 2 -> /dev/pts/7
/tmp>rm r
/tmp>L /proc/19925/fd
total 0
lrwx------ 1 root root 64 Jan 19 13:10 0 -> /dev/pts/7
l-wx------ 1 root root 64 Jan 19 13:10 1 -> /tmp/r (deleted)
lrwx------ 1 root root 64 Jan 19 13:10 2 -> /dev/pts/7
/tmp>ln /proc/19925/fd/1 r2
ln: /proc/19925/fd/1: warning: making a hard link to a symbolic link is not portable
ln: create hard link `r2' to `/proc/19925/fd/1': Invalid cross-device link

I think one has to use lsof, ps and/or fuser and then kill.

-- v --

v@iki.fi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Jan 23 2002 - 21:00:32 EST