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

Re: deleting content of /tmp



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03/24/07 21:22, Roberto C. Sánchez wrote:
> 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;
> }
> 

Ah, you're deleting an open file!

The app, then, that deletes an open file is poorly written.

> 
> You just need to compare the df output for the partition on which the
> program is running.
> 
> Regards,
> 
> -Roberto


- --
Ron Johnson, Jr.
Jefferson LA  USA

Give a man a fish, and he eats for a day.
Hit him with a fish, and he goes away for good!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGBd8eS9HxQb37XmcRAuarAKDBkAXd+oVtWOZUlHUfavXwk3ESmQCgoT89
rWwFhNRoQvtmDrayDPqc/58=
=PQjS
-----END PGP SIGNATURE-----



Reply to: