This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

1.5.5.1 unlink() unable to remove an open file.


hi all,

	I am having a problem with unlink() system call. If the file is
currently open by some other process then unlink() is unable to delete
that file ( shown in 'ls' to that directory) but returns successfull! But
after all filedescriptors open to that file are closed, the file is
removed.
But in linux, the 'file' is removed immediately after unlink() 
call, irrespective of how many other open filedescriptors are there for
the 'file'.
Is there any specific reason for such a behaviour by cygwin???

here are the test program (s) for the problem:

/*************open_file.c*****************/
#include<stdio.h>
int main()
{
	int i;
	FILE *p;
	p=fopen("test_file","r");
	if(!p)
		perror("fopen");
	else
		printf("fopen successful!!!\n");
	scanf("%d",&i);	/*prevent program termination*/
	/*close the file*/
	fclose(p);
	return 0;
}
/*********************************************/

/************* unlink_file.c******************/
#include<stdio.h>
int main()
{
	int i;
	i=unlink("test_file");
	if(i)
		perror("unlink");
	else
		printf("unlink successful!!!\n");
	printf("exiting main...\n");
	return 0;
}
/***********************************************/

How to run?
--------------
1. copy  these two files in some dir
2. create a file named 'test_file' withing the same dir
3. compile both the files.
4. first, run open_file.exe in a bash shell (after open it should wait for
input, don't give any input at this point)
5. open a new shell and run unlink_file.exe (it should be successful)
6. type 'ls' on the shell , the file 'test_file' still shown.
7. now terminate open_file.exe program by giving some input, and 'ls'
again on the dir. now 'test_file' is not shown and deleted!!!

with thanks and regards,

ghanshyam




--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]