zoukankan      html  css  js  c++  java
  • linux之unlink函数解析

    [lingyun@localhost unlink]$ cat unlink.c 
    /*********************************************************************************
     *      Copyright:  (C) 2013 fulinux<fulinux@sina.com> 
     *                  All rights reserved.
     *
     *       Filename:  unlink.c
     *    Description:  This file 
     *                 
     *        Version:  1.0.0(08/04/2013~)
     *         Author:  fulinux <fulinux@sina.com>
     *      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 ");
        sleep(15);
        printf("done ");
        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]$ 

  • 相关阅读:
    Struts2 helloWorld
    Python学习笔记基础汇总部分
    从控制台读入,典型的装饰者模式
    随机数产生方法小知识点
    Struts2基础知识
    面向对象原则之GOF是招式,九大原则才是精髓
    静态工厂方法
    单例模式singleton
    J2SE基础夯实系列之JDBC,链接数据库实例代码
    Ubuntu 12.04 下安装ssh 服务遇到的问题以及总结
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3236902.html
Copyright © 2011-2022 走看看