Hacker News new | ask | show | jobs
by DSMan195276 3084 days ago
I actually tried this idea when I read their initial comment. Unfortunately (And this is obvious when you realize it) you can't `unlink` or `rmdir` a non-empty directory. Also, though `rmdir` can work while you still have an open reference to the directory, once you do a `rmdir` you are not allowed to add any new files to the directory, making it essentially useless.

I think the best way would just to make sure you mount a `tmpfs` somewhere and make a directory on that (With something like your PID in the name). Then have some supervisor program periodically remove all directories with PIDs that are not longer running (Along with having the programs themselves clean it up if they have the opportunity). That's probably the best you can get, I don't think there's anyway to make the directory get automatically cleaned-up by the kernel.

1 comments

> once you do a `rmdir` you are not allowed to add any new files to the directory

Ah, go figure. I had a feeling you'd run into something like that.

As for your tmpfs idea... you could do something with autofs to get automatic cleanup.

Yeah, it's unfortunate, it'd be pretty cool if you could pull something off like that. And conceptually it's not much different then what you can do with files already.

And autofs sounds like it could do it. I think the simplest implementation wouldn't be very complicated though, you could probably do it with a bash script that cross-checks folder names with running processes every 5 minutes or so. Assuming most programs clean-up after themselves, it only needs to handle programs that do an abnormal exit like SIGKILL. Of course, if that script has problems you'd be in for a bad time.