Nguyễn Thái Ngọc Duy [off-list ref] writes:
The lock-based version has an advantage that the following gc runs
will never see partial gc.log. But it requires some more hook at
atexit() and maybe signal handler.
This version avoids that, and gc.log can be kept even if gc is
SIGKILL'd (unlikely because gc itself does not do anything that can
upset the kernel), but then it's racy.
Given that you are only interested in an non-empty output, and also
you want to avoid running an auto-gc when another one is already
running, I wonder if that "never see partial" property really
matters.
In any case, "an alternative could be to avoid lockfile and not
bothering to remove an empty one" was idea from Michael, so let's CC
him back in the loop.
I think I perfer the lock-based version.
It certainly does look more familiar to me, too ;-)