I want to set a timeout to the less(1)
command on our company's production server. Everyday we produce large log files on it, and despite the nightly batch job to archive/remove them, we sometimes get alerted on high disk usage because a (long-)running process can prevent a file from getting unlink(2)
-ed physically due to the reference-counting semantics of POSIX filesystems.
To avoid the most common cases of such annoyances, I wrote a wrapper of less
which runs it under timeout(1)
so that idle less
processes get automatically killed after several hours without keeping open files in the filesystem.
But it turned out to play badly with man(1)
: when the wrapper is launched by the man
command via the PAGER
environment variable, it stopped responding to any keyboard inputs. Here is a minimal reproducible test case:
$ PAGER='timeout 12h /bin/less' man man
After running this, ps fx
output looks like this:
19415 pts/1 SNs 0:00 \_ -bash
19854 pts/1 SN+ 0:00 \_ man man
19867 pts/1 SN 0:00 \_ timeout 12h /bin/less
19869 pts/1 TN 0:00 \_ /bin/less
and I could only kill -KILL 19869
to regain an access to the terminal.
What did I get wrong here?
Why is the less
process in the T
state, as opposed to S
?
man
/less
in the background throughCtrl+Z
. Did you do that to run yourps
command? That would putless
in a T state... Usingtimeout
inPAGER
seems to work as expected on my OpenBSD system.