Re: [vox] cat and >> - how does it know?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [vox] cat and >> - how does it know?
Cool. Nice catch, Pete. I got a test program to work. > still kills the
file, though. >> doesn't. Like someone suggested, perhaps BASH should
check to see if there's any data before writing to a file.
-Mark
On Thu, 13 Jun 2002, Peter Jay Salzman wrote:
> begin nbs <nbs@sonic.net>
> > On Thu, Jun 13, 2002 at 04:21:53PM -0700, Mark K. Kim wrote:
> > > File locking?
> > >
> >
> > Who locks the file?
> >
> > And just because some file that "cat" is opening for read is "locked,"
> > why should that mean that it's the same file (input == output)
> >
> > :)
>
> bill,
>
> here is what happens behind the scenes (i deleted memory managing and shared
> library stuff):
>
> execve("/bin/cat", ["cat", "ron.tmp"], [/* 25 vars */]) = 0
> uname({sys="Linux", node="satan", ...}) = 0
> brk(0) = 0x804b048
>
> ...
>
> fstat64(1, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
> open("ron.tmp", O_RDONLY|O_LARGEFILE) = 3
> fstat64(3, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
> write(2, "cat: ", 5) = 5
> write(2, "ron.tmp: input file is output fi"..., 34) = 34
> write(2, "\n", 1) = 1
> close(3) = 0
> close(1) = 0
> _exit(1) = ?
>
> before erroring out, 2 calls to fstat64 are made.
>
> now if you look at man fstat, you'll see a field called "inode".
>
> you know what an inode is, so you can infer the rest... :-)
>
> pete
>
> ps- i was under the impression that this sort of thing killed the temp
> file. i'm surprised the check is made.
>
> pps- there's no significance to "ron.tmp". i had a a text file named
> "ron" and made a copy of it, ron.tmp to do this experiment with since i
> was expecting the file to be blown away.
> _______________________________________________
> vox mailing list
> vox@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox
>
--
Mark K. Kim
http://www.cbreak.org/
PGP key available upon request.
_______________________________________________
vox mailing list
vox@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox
|