No-bull Way to Work Temp Files in UNIX
Home
About PdN
Philtered Team
Published
Projects
Wireless
0xC0D3
Tech Support
Links

   Many flavours of Unix offer a host of system calls which can be used for manipulating temporary files. Why on earth would you ever need to use special calls for manipulating temporary files?

Well, consider the fact that you are on a multi-user, multithreaded OS. Hundreds, possibly thousands of processes are running at any one time. Many of these processes are forked, daemons, and/or sleeping. Now imagine if user-a is running a process called foo. This program needs to process large amounts of data one line at a time; as it processes each line it must save it somewhere for reprocessing. Well, this is simple, just create a file in the temp volume and store the data there.

No problem so far, right? Well, what if user-b wants to run the same process for a dataset of his own. The program foo will attempt to create an identical file in the temp volume and write to it. Well, now the problem is obvious! The result will be two very unhappy users.

Note that this is a tutorial only. The sample code included is niether secure nor threadsafe That might be a nice article for a future date.

PDF Version *RECOMMENDED*

Postscript Version *RECOMMENDED*

Html Version

StarWriter Version

Text Version

TarBall Including Sample Source Code