On 11/03/2011 14:23, McKown, John wrote:
There's a discussion going on over on the MVS-OE forum (which I started) about the /tmp subdirectory. It's gone away from my original towards how to keep it clean. So I thought I'd ask the UNIX wizards over here what the "industry standard" is.
I don't speak for "industry", but here are some Linux standards: http://www.pathname.com/fhs/pub/fhs-2.3.html#TMPTEMPORARYFILES http://www.pathname.com/fhs/pub/fhs-2.3.html#VARTMPTEMPORARYFILESPRESERVEDBETWEE
One thing mentioned by a person boiled down to "delete all the files in /tmp which belong to a specific user when the last process which is running with that UID terminates" (rephrased by me). This got me to thinking. Is there any need for a file in /tmp to exist when there is no process running by a given user?
On a strict reading of the above, you can't rely on a /tmp file existing "between invocations of the program", in other words when a file isn't actively held open by a process. This would break many many shell scripts I've read and written over the years :) The typical way to clear up /tmp is with the tmpwatch utility, fired from cron, which selects files to delete based on their last access timestamp. Some distros go further and clean out /tmp completely on every boot.
find /tmp -type f -exec ls -ln {} \; |\ awk '{print $3;}'|\ sort -u|\ while read XUID; do echo Processing UID: $XUID; ps -u $XUID -U $XUID>/dev/null || find /tmp -type f -uid $XUID -exec rm; done
I can see this approach yielding a lot of false negatives; i.e. leaving files in place because UID has some unrelated process running. If you're desperate to have a tidy /tmp, a frequent call to tmpwatch along these lines might work: tmpwatch --atime -all --fuser 6 /tmp This 6-hour deadline is a lot more severe that Redhat's default of 10 days. Before doing that, however, I'd question why the /tmp directory is so space-constrained. If software isn't cleaning up its own stuff, fix it! One further trick is to unlink a /tmp file while it's open, which guarantees cleanup as soon as the process ends. Cheers, Phil ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 ---------------------------------------------------------------------- For more information on Linux on System z, visit http://wiki.linuxvm.org/