#include <windows.h>
#include <stdio.h>
int main(void)
{
HANDLE hfile1 = CreateFile("c:\\1.txt" ,
FILE_WRITE_DATA ,
FILE_SHARE_READ | FILE_SHARE_WRITE ,
NULL,
CREATE_ALWAYS ,
0,
0
);
if (hfile1 == INVALID_HANDLE_VALUE)
{
printf("create file 1 failed! err %u\n" , GetLastError());
system("pause");
return 0 ;
}
CloseHandle(hfile1);
if (!CreateHardLink("c:\\2.txt" , "c:\\1.txt" , NULL))
{
printf("create hardlink failed err %u\n" , GetLastError());
system("pause");
return 0 ;
}
hfile1 = CreateFile("c:\\2.txt" ,
FILE_WRITE_DATA | FILE_READ_DATA | DELETE,
0,
NULL,
OPEN_EXISTING ,
0,
0
);
printf("try to kill c:\\1.txt!\n");
while(TRUE)
{
Sleep(100000);
}
}
评论