[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: deleting content of /tmp



On Sat, Mar 24, 2007 at 08:54:15PM -0500, Ron Johnson wrote:
> On 03/24/07 20:45, CaT wrote:
> > On Sat, Mar 24, 2007 at 08:38:54PM -0500, Ron Johnson wrote:
> >>> However, realize that some programs create a file /tmp and then promptly
> >>> unlink it, thus causing the file to take up space even though it does
> >>> not have a directory entry.
> >> How's that?
> > 
> > UNIX does not deallocate disk space until all opens are closed.
> 
> Sure, if there are {hard,soft} links on the file.  What if it's a
> no-links file?
> 
If there is still an open file descriptor, it will still be there.  The
disk space is only relinquished on the closing of all file descriptors.

The following little C program will illustrate:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
  FILE *f;

  f = fopen("check_my_size", "w");
  int i;
  for (i = 0; i < 1000000; ++i)
    fprintf(f, "This is just filler for the file");
  system("ls -lk check_my_size");
  printf("Checking utilization:\n");
  fflush(stdout);
  system("df -k");
  sleep(2);
  printf("Unlinking file\n");
  fflush(stdout);
  unlink("check_my_size");
  system("ls -lk check_my_size");
  printf("Checking utilization:\n");
  fflush(stdout);
  system("df -k");
  sleep(2);
  printf("Closing file\n");
  fflush(stdout);
  fclose(f);
  system("ls -lk check_my_size");
  printf("Checking utilization:\n");
  fflush(stdout);
  system("df -k");
  return 0;
}


You just need to compare the df output for the partition on which the
program is running.

Regards,

-Roberto
-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Attachment: signature.asc
Description: Digital signature


Reply to: