02-08-2008
I'm not sure about what or why you're doing things...?
This is how unlink (remove() in C or rm in shell ) works: it deletes the file from the directory, but the file's data and any currently open file descriptors can see that data.
When the last file descriptor to the file close, then the data itself goes away.
This means process #1 can keep on reading the file. When it is done with the file -- and if it was deleted by process #2, then the file's data will no longer be accessible.
If process #2 opens another file with the same file name it will not affect process #1's data.
So, why are you doing this? The only reason I know of to delete a file that is open is to hide it from all other processes. It's a good security measure.
You can achieve synchronization using a lock file - another file that tells process #1 and process #2 when they can do something with the data - if you need it.
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I know I saw a couple posts about this a long time ago, but could not find them with search. Please refresh my memory.
-Chuck (1 Reply)
Discussion started by: 98_1LE
1 Replies
2. Shell Programming and Scripting
Hi,
Actually I am want to cut the three fields of "file-nr" file.
$ cat /proc/sys/fs/file-nr
638 219 52270
I want to assign these value to diffrent varibales as follow:-
a=638
b=219
c=52270
I tried to use cut command for this purpose and also tried to squeeze all sapces... (6 Replies)
Discussion started by: bisla.yogender
6 Replies
3. Shell Programming and Scripting
Guys,
My log files stored in the date format format below(log_20080714072942):
TIMESTAMP=`date +%Y%m%d%H%M%S`
LOG=/log/log_${TIMESTAMP}.log
I'm looking for a shell script which deletes all files which is older than 3 months from today.
Regards,
Bhagat (3 Replies)
Discussion started by: bhagat.singh-j
3 Replies
4. Solaris
I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command.
I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file.
Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies
5. Shell Programming and Scripting
I'm trying to write a script that will do an ls of a location, echo it into a file, and then read that file and selectively delete files/folders, so it would go something like this:
cd $CLEAN_LOCN
ls >>$TMP_FILE
while read LINE
do
if LINE = $DONTDELETE
skip
elseif LINE =... (2 Replies)
Discussion started by: MaureenT
2 Replies
6. Shell Programming and Scripting
Hi....
I have a need of script to do delete row whenever condition is true....
2.16 (3) 1 3 9999 0 (1) (0)
34.42 (4) 1 3 9999 37 (2) (3)
34.38 (4) 1 3 9999 64 (2) (3)
34.4 (4) 1 3 1 ... (13 Replies)
Discussion started by: nex_asp
13 Replies
7. Shell Programming and Scripting
Hi Guru's
The script has to read an entry from one file and delete the set of lines form other file. Below is the format of the file. In the below example, script should read the entries from input file 2 and delete the entries from input file 1.
Input file 1
cn: test@test1.com
abc:... (7 Replies)
Discussion started by: Samingla
7 Replies
8. UNIX for Dummies Questions & Answers
I have file called "text". The contents are as below :
aaa
bbb
ccc
ddd
eee
ffff
ddd
hhhh
iiii
I want to read this file without opening and and delete the last line. How can it be done? (4 Replies)
Discussion started by: the_hunter
4 Replies
9. UNIX for Beginners Questions & Answers
i want to give users the ability to create write and read files in other user directory , but not to have option to delete the file after created ( sticky bit not going to work here ... ) for example :
i have user : manager with directory repository
i have user : worker1 that need to write... (4 Replies)
Discussion started by: umen
4 Replies
10. Shell Programming and Scripting
I have a CSV file with hdfs directories, hive tables and hbase tables.
1. first column - hdfs directories
2. second column - hive tables
3. third column - hbase tables
I have to check the csv file and look for the first column and delete the hdfs directory from the hdfs path, now... (2 Replies)
Discussion started by: shivamayam
2 Replies
LEARN ABOUT FREEBSD
close
CLOSE(2) BSD System Calls Manual CLOSE(2)
NAME
close -- delete a descriptor
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <unistd.h>
int
close(int fd);
DESCRIPTION
The close() system call deletes a descriptor from the per-process object reference table. If this is the last reference to the underlying
object, the object will be deactivated. For example, on the last close of a file the current seek pointer associated with the file is lost;
on the last close of a socket(2) associated naming information and queued data are discarded; on the last close of a file holding an advisory
lock the lock is released (see further flock(2)). However, the semantics of System V and IEEE Std 1003.1-1988 (``POSIX.1'') dictate that all
fcntl(2) advisory record locks associated with a file for a given process are removed when any file descriptor for that file is closed by
that process.
When a process exits, all associated file descriptors are freed, but since there is a limit on active descriptors per processes, the close()
system call is useful when a large quantity of file descriptors are being handled.
When a process forks (see fork(2)), all descriptors for the new child process reference the same objects as they did in the parent before the
fork. If a new process is then to be run using execve(2), the process would normally inherit these descriptors. Most of the descriptors can
be rearranged with dup2(2) or deleted with close() before the execve(2) is attempted, but if some of these descriptors will still be needed
if the execve fails, it is necessary to arrange for them to be closed if the execve succeeds. For this reason, the call ``fcntl(d, F_SETFD,
FD_CLOEXEC)'' is provided, which arranges that a descriptor will be closed after a successful execve; the call ``fcntl(d, F_SETFD, 0)''
restores the default, which is to not close the descriptor.
RETURN VALUES
The close() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate
the error.
ERRORS
The close() system call will fail if:
[EBADF] The fd argument is not an active descriptor.
[EINTR] An interrupt was received.
[ENOSPC] The underlying object did not fit, cached data was lost.
[ECONNRESET] The underlying object was a stream socket that was shut down by the peer before all pending data was delivered.
In case of any error except EBADF, the supplied file descriptor is deallocated and therefore is no longer valid.
SEE ALSO
accept(2), closefrom(2), execve(2), fcntl(2), flock(2), open(2), pipe(2), socket(2), socketpair(2)
STANDARDS
The close() system call is expected to conform to ISO/IEC 9945-1:1990 (``POSIX.1'').
HISTORY
The close() function appeared in Version 7 AT&T UNIX.
BSD
September 11, 2013 BSD