Re: Deleting a file while other script still appending to
- From: chas.owens@xxxxxxxxx (Chas. Owens)
- Date: Thu, 7 Feb 2008 09:01:56 -0500
On Feb 7, 2008 5:54 AM, Mahdi A Sbeih <mahdi.sbeih@xxxxxxx> wrote:
Hi all,snip
I have a script that logs activities to a txt log file. I noticed that
when deleting the file from another window or shell, the script stops
writing to the file. I was expecting something like the unix shell,
which is creating a new file and appending to it.
After few seconds, and from another terminal, delete the file that wassnip
created by the script, notice that the script won't stop or error out,
but in the same time no new file is created.
When you unlink* a file you are telling the filesystem that the name
that is associated with that inode should no longer be used, but the
space is not reclaimed so long as there is still a reference to the
inode. This reference can be another link created by the link syscall
or an open file handle. A common trick used by daemons is to open
temporary files in read/write mode and then unlink them. By doing
this they can ensure that no other process can read or write to the
file. This is what is happening to you. What you need to do is open
the file for appending right before each write and close it right
after the write.
* There is no such thing as delete in POSIX filesystems; normally it
doesn't matter, but in this case you need to understand what is really
happening.
.
- References:
- Deleting a file while other script still appending to
- From: Mahdi A Sbeih
- Deleting a file while other script still appending to
- Prev by Date: Deleting a file while other script still appending to
- Next by Date: Re: Help on perl alarm
- Previous by thread: Deleting a file while other script still appending to
- Index(es):
Relevant Pages
|