How do temporary folders work?

Asked

Viewed 137 times

5

I was wondering about that today. In both Unix and Windows operating systems, we have a specific location where temporary files of all kinds are played.

It is obvious to think that if the folder is temporary, the data will only be there for a certain time.

But now there are many doubts:

  • How and when these files are removed? Is there any configuration on the operating system regarding this?

  • Does it have anything to do with system reboot? If so, what about servers, which are usually rarely rebooted?

  • Is there any way to flag on the operating system (at least on Windows and Linux) that other folders will also be considered temporary?

1 answer

3


Depends on operating system.

How and when these files are removed? Is there any configuration on the operating system regarding this?

On Windows do not have anything automatic, you should remove manually. Cleaning what is temporary should be enforcement responsibility. Putting something in there just means it can disappear at any time without application control. Obviously if the file is in use no one can remove it.

On Linux it depends on where you place it and the distribution. On /tmp, although it is recommended to delete when there is boot, nothing guarantees that it is done in its distribution. No var/tmp stay as long as necessary until some intervention of the application or the "owner" of the machine, like Windows.

If you don’t add a specific application to take care of it and your application doesn’t take care of it, in general it will fill.

This is just a convention not to leave temporary files scattered everywhere and you know that erasing there gets rid of them. Too bad many programmers ignore this recommendation and spread files everywhere.

Does it have anything to do with system reboot? If so, what about servers, which are usually rarely rebooted?

It’s on Linux, but anyway it’s your problem to fix it, so it doesn’t matter if it’s a server.

Is there any way to flag on the operating system (at least on Windows and Linux) that other folders will also be considered temporary?

As far as I know there is no standard, but in Linux it can always be moved if the person wants a lot and is empowered. And it doesn’t even matter if something like this exists. Windows allows you to change the location of the folder.

How to use this folder in my application?

This was the most important question not asked in a programming Q&A.

On Linux it is safe to always use /tmp and /var/tmp to put your temporary files.

In Windows the correct is to see where the folder is already that it can be configured by the user (there can only be one), through API provided in the language you are using or by the environment variable TEMP.

If you do not do so and feel you should put them elsewhere at least ensure that they are cleaned in any circumstances, even when the application breaks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.