title: auto delete file on linux
body: <p>I am trying to do a file be deleted when a program ends. I remember that before I could put the <code>unlink()</code> before the first <code>close()</code> and I don't need reopen the file.</p>
  
  <p>What I expect: The file is erased after the program ends.</p>
  
  <p>What is happening: The file is erased when the call to unlink happens the file is erased.</p>
  
  <p>My sample program:</p>
  
  <pre><code>int main()
  {
      int fd = open(argv[1], O_CREAT);
      int x = 1;
      write(fd, "1234\n", 5);
      close(fd);
  
      fd = open(argv[1], 0);
      unlink(argv[1]);
  
      while (x &lt;= 3)
      {
        int k;
        scanf(" %d", &amp;k);
  
        x++;
      }
  
      close(fd);
      return 0;
  }
  </code></pre>
  
  <p>Has a way that I can <code>open()</code> the file, interact with it and on <code>close()</code> delete the file from harddisk? I'm using fedora linux 18.</p>
  
  <p>I need know the name of the file that I did open in this way because it will be used by another application.</p>