While looking at the issues around temporary files I noticed that some
shell scripts create a lot of temporary files...
... which leads to the question: Wouldn't it be better to create one
temporary directory with a random name and then create all temporary
files in that directory ?

AFAIK the advantages are:
- This should be faster in cases that /tmp is clogged with thousands
of files. I've seen that in some caases /tmp on Solaris can have
50000+ actively used files (not all from ksh93) ... which borders IMO
near insanity to handle that (usual suggestion is to set TMPDIR to
something like /tmp/$LOGNAME/ in /etc/profile). This assume we open
the directory using |openat()| to avoid that the shell always needs to
do a full path lookup starting from ${TMPDIR}.
- The files in the temporary directory can be picked in a more
descriptive fashion, e.g. made out of
(namespace, functionname and subshelllevel are only used if
appiliable/used and "counter" is an |uint64_t| which is increased for
each temporary file. The <pid> part names sure this is unique even if
a subshell called |fork()| and then fork'ed child processes) or
something like that.

- It's harder to delete the directory
- At least one extra syscall is required (|mkdir()|)
- More code, making ksh93 bigger



  __ .  . __
 (o.\ \/ /.o) roland.ma...@nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
ast-developers mailing list

Reply via email to