From APUE
#include <unistd.h> int unlink(const char *pathname);
Only when the link count reaches 0 can the contents of the file be deleted. One other condition prevents the contents of a file from being deleted: as long as some process has the file open, its contents will not be deleted. When a file is closed, the kernel first checks the count of the number of processes that have the file open. If this count has reached 0, the kernel then checks the link count; if it is 0, the file’s contents are deleted.
If a file is being used by
execve()
in a process, does it count it as "the process has the file open"?If some process has the file being open or
execve()
ed, willunlink()
immediately return 0 or -1, or wait till the process closes the file orexecve()
finishes running and performs its job?