从结果可以得出,在⽂件打开的情况下unlink()并不会⽴即删除,并且对⽂件依然可以进⾏读写操作,在进程结束之后⽂件就会被删除掉!
六、函数说明
UNLINK(2)                  BSD System Calls Manual                  UNLINK(2)
NAME
unlink, unlinkat -- remove directory entry
SYNOPSIS
#include <unistd.h>
int
unlink(const char *path);
int
unlinkat(int fd, const char *path, int flag);
DESCRIPTION
The unlink() function removes the link named by path from its direc-
tory and decrements the link count of the file which was referenced
by the link.  If that decrement reduces the link count of the file
to zero, and no process has the file open, then all resources asso-
ciated with the file are reclaimed.  If one or more process have the
file open when the last link is removed, the link is removed, but
the removal of the file is delayed until all references to it have
been closed.
The unlinkat() system call is equivalent to unlink() or rmdir()
except in the case where path specifies a relative path.  In this
case the directory entry to be removed is determined relative to the
directory associated with the file descriptor fd instead of the cur-
rent working directory.
The values for flag are constructed by a bitwise-inclusive OR of
flags from the following list, defined in <fcntl.h>:
AT_REMOVEDIR
Remove the directory entry specified by fd and path as a
directory, not a normal file.
If unlinkat() is passed the special value AT_FDCWD in the fd parame-
ter, the current working directory is used and the behavior is iden-
tical to a call to unlink or rmdir respectively, depending on
whether or not the AT_REMOVEDIR bit is set in flag.
RETURN VALUES
Upon successful completion, a value of 0 is returned.  Otherwise, a
value of -1 is returned and errno is set to indicate the error.
ERRORS
The unlink() system call will fail if:
[EACCES]          Search permission is denied for a component of
the path prefix.
[EACCES]          Write permission is denied on the directory con-
taining the link to be removed.
[EBUSY]            The entry to be unlinked is the mount point for a
mounted file system.
[EBUSY]            The file named by the path argument cannot be
unlinked because it is being used by the system
or by another process.
system的头文件[EFAULT]          Path points outside the process's allocated
address space.
[EIO]              An I/O error occurs while deleting the directory
entry or deallocating the inode.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。