linux之unlink函数解析

[lingyun@localhost unlink]$ cat unlink.c 
/*********************************************************************************
 *      Copyright:  (C) 2013 fulinux<[email protected]
 *                  All rights reserved.
 *
 *       Filename:  unlink.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(08/04/2013~)
 *         Author:  fulinux <[email protected]>
 *      ChangeLog:  1, Release initial version on "08/04/2013 10:37:14 AM"
 *                 
 ********************************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>




/********************************************************************************
 *  Description:
 *   Input Args:
 *  Output Args:
 * Return Value:
 ********************************************************************************/
int main (void)
{
    if(open("tempfile", O_RDWR) < 0)
    {
        perror("open");
        exit(1);
    }
    if(unlink("tempfile") < 0)
    {
        perror("unlink");
        exit(1);
    }


    printf("file unlinked\n");
    sleep(15);
    printf("done\n");
    exit(0);


} /* ----- End of main() ----- */


[lingyun@localhost unlink]$ gcc unlink.c 
[lingyun@localhost unlink]$ touch tempfile
[lingyun@localhost unlink]$ ./a.out &
[1] 30273
[lingyun@localhost unlink]$ file unlinked


[lingyun@localhost unlink]$ ls tempfile
ls: cannot access tempfile: No such file or directory
[lingyun@localhost unlink]$ done


[1]+  Done                    ./a.out
[lingyun@localhost unlink]$ 

你可能感兴趣的:(linux)