Coreutils timeout(1) plays badly with man/less












2














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?










share|improve this question






















  • Show us the wrapper please
    – Rui F Ribeiro
    2 days ago










  • The only way I can reproduce this is if I temporarily put man/less in the background through Ctrl+Z. Did you do that to run your ps command? That would put less in a T state... Using timeout in PAGER seems to work as expected on my OpenBSD system.
    – Kusalananda
    2 days ago












  • I suspect that the less process is getting suspended because it isn' in the foreground (so it receives SIGTTIN when it tries to read from stdin). @Kusalananda
    – Gilles
    2 days ago












  • @Gilles Had you given a comment a bit earlier... I just posted my findings as a solution to my own question.
    – nodakai
    2 days ago
















2














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?










share|improve this question






















  • Show us the wrapper please
    – Rui F Ribeiro
    2 days ago










  • The only way I can reproduce this is if I temporarily put man/less in the background through Ctrl+Z. Did you do that to run your ps command? That would put less in a T state... Using timeout in PAGER seems to work as expected on my OpenBSD system.
    – Kusalananda
    2 days ago












  • I suspect that the less process is getting suspended because it isn' in the foreground (so it receives SIGTTIN when it tries to read from stdin). @Kusalananda
    – Gilles
    2 days ago












  • @Gilles Had you given a comment a bit earlier... I just posted my findings as a solution to my own question.
    – nodakai
    2 days ago














2












2








2


0





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?










share|improve this question













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?







terminal process-management timeout






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









nodakainodakai

247110




247110












  • Show us the wrapper please
    – Rui F Ribeiro
    2 days ago










  • The only way I can reproduce this is if I temporarily put man/less in the background through Ctrl+Z. Did you do that to run your ps command? That would put less in a T state... Using timeout in PAGER seems to work as expected on my OpenBSD system.
    – Kusalananda
    2 days ago












  • I suspect that the less process is getting suspended because it isn' in the foreground (so it receives SIGTTIN when it tries to read from stdin). @Kusalananda
    – Gilles
    2 days ago












  • @Gilles Had you given a comment a bit earlier... I just posted my findings as a solution to my own question.
    – nodakai
    2 days ago


















  • Show us the wrapper please
    – Rui F Ribeiro
    2 days ago










  • The only way I can reproduce this is if I temporarily put man/less in the background through Ctrl+Z. Did you do that to run your ps command? That would put less in a T state... Using timeout in PAGER seems to work as expected on my OpenBSD system.
    – Kusalananda
    2 days ago












  • I suspect that the less process is getting suspended because it isn' in the foreground (so it receives SIGTTIN when it tries to read from stdin). @Kusalananda
    – Gilles
    2 days ago












  • @Gilles Had you given a comment a bit earlier... I just posted my findings as a solution to my own question.
    – nodakai
    2 days ago
















Show us the wrapper please
– Rui F Ribeiro
2 days ago




Show us the wrapper please
– Rui F Ribeiro
2 days ago












The only way I can reproduce this is if I temporarily put man/less in the background through Ctrl+Z. Did you do that to run your ps command? That would put less in a T state... Using timeout in PAGER seems to work as expected on my OpenBSD system.
– Kusalananda
2 days ago






The only way I can reproduce this is if I temporarily put man/less in the background through Ctrl+Z. Did you do that to run your ps command? That would put less in a T state... Using timeout in PAGER seems to work as expected on my OpenBSD system.
– Kusalananda
2 days ago














I suspect that the less process is getting suspended because it isn' in the foreground (so it receives SIGTTIN when it tries to read from stdin). @Kusalananda
– Gilles
2 days ago






I suspect that the less process is getting suspended because it isn' in the foreground (so it receives SIGTTIN when it tries to read from stdin). @Kusalananda
– Gilles
2 days ago














@Gilles Had you given a comment a bit earlier... I just posted my findings as a solution to my own question.
– nodakai
2 days ago




@Gilles Had you given a comment a bit earlier... I just posted my findings as a solution to my own question.
– nodakai
2 days ago










1 Answer
1






active

oldest

votes


















2














Answering to my own question, as I couldn't really find any hints on this via my googling.



strace(1) could actually reveal that SIGTTOU had been sent to the less process.




  • https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html



This is similar to SIGTTIN, but is generated when a process in a background job attempts to write to the terminal or set its modes. ...snip...




And apparently timeout(1) by default puts the process under management into background:




  • https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html



--foreground



Don’t create a separate background program group, so that the managed command can use the foreground TTY normally. ...snip...




So the solution to my problem was



$ PAGER='/bin/timeout --foreground 12h /bin/less' man man


(and something equivalent in my wrapper)






share|improve this answer























  • Hmmm... I wonder it seemed to be working on my system then?
    – Kusalananda
    2 days ago






  • 1




    @Kusalananda /usr/bin/man is a completely different beast on OpenBSD than on linux, especially since they got rid of groff.
    – mosvy
    2 days ago






  • 1




    less still doesn't work right with timeout; when killed by a signal, less will fail to restore the stty/termios settings, and you will be left with having to do a blind reset or stty sane; try timeout 2s less ~/.bashrc.
    – mosvy
    2 days ago






  • 1




    @mosvy this (minimal example) wrapper seems to fix it for me g=$(stty -g); timeout 2s less ~/.bashrc || stty "$g"
    – roaima
    2 days ago












  • Nodakai, on my Debian version of timeout the man page and effect appear to contradict the GNU info page you referenced. With timeout 12h less the page works as I would expect - until the timeout gets reached. Specifically, the --foreground option is not required unless timeout itself is not being run directly from a terminal.
    – roaima
    2 days ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492941%2fcoreutils-timeout1-plays-badly-with-man-less%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Answering to my own question, as I couldn't really find any hints on this via my googling.



strace(1) could actually reveal that SIGTTOU had been sent to the less process.




  • https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html



This is similar to SIGTTIN, but is generated when a process in a background job attempts to write to the terminal or set its modes. ...snip...




And apparently timeout(1) by default puts the process under management into background:




  • https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html



--foreground



Don’t create a separate background program group, so that the managed command can use the foreground TTY normally. ...snip...




So the solution to my problem was



$ PAGER='/bin/timeout --foreground 12h /bin/less' man man


(and something equivalent in my wrapper)






share|improve this answer























  • Hmmm... I wonder it seemed to be working on my system then?
    – Kusalananda
    2 days ago






  • 1




    @Kusalananda /usr/bin/man is a completely different beast on OpenBSD than on linux, especially since they got rid of groff.
    – mosvy
    2 days ago






  • 1




    less still doesn't work right with timeout; when killed by a signal, less will fail to restore the stty/termios settings, and you will be left with having to do a blind reset or stty sane; try timeout 2s less ~/.bashrc.
    – mosvy
    2 days ago






  • 1




    @mosvy this (minimal example) wrapper seems to fix it for me g=$(stty -g); timeout 2s less ~/.bashrc || stty "$g"
    – roaima
    2 days ago












  • Nodakai, on my Debian version of timeout the man page and effect appear to contradict the GNU info page you referenced. With timeout 12h less the page works as I would expect - until the timeout gets reached. Specifically, the --foreground option is not required unless timeout itself is not being run directly from a terminal.
    – roaima
    2 days ago


















2














Answering to my own question, as I couldn't really find any hints on this via my googling.



strace(1) could actually reveal that SIGTTOU had been sent to the less process.




  • https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html



This is similar to SIGTTIN, but is generated when a process in a background job attempts to write to the terminal or set its modes. ...snip...




And apparently timeout(1) by default puts the process under management into background:




  • https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html



--foreground



Don’t create a separate background program group, so that the managed command can use the foreground TTY normally. ...snip...




So the solution to my problem was



$ PAGER='/bin/timeout --foreground 12h /bin/less' man man


(and something equivalent in my wrapper)






share|improve this answer























  • Hmmm... I wonder it seemed to be working on my system then?
    – Kusalananda
    2 days ago






  • 1




    @Kusalananda /usr/bin/man is a completely different beast on OpenBSD than on linux, especially since they got rid of groff.
    – mosvy
    2 days ago






  • 1




    less still doesn't work right with timeout; when killed by a signal, less will fail to restore the stty/termios settings, and you will be left with having to do a blind reset or stty sane; try timeout 2s less ~/.bashrc.
    – mosvy
    2 days ago






  • 1




    @mosvy this (minimal example) wrapper seems to fix it for me g=$(stty -g); timeout 2s less ~/.bashrc || stty "$g"
    – roaima
    2 days ago












  • Nodakai, on my Debian version of timeout the man page and effect appear to contradict the GNU info page you referenced. With timeout 12h less the page works as I would expect - until the timeout gets reached. Specifically, the --foreground option is not required unless timeout itself is not being run directly from a terminal.
    – roaima
    2 days ago
















2












2








2






Answering to my own question, as I couldn't really find any hints on this via my googling.



strace(1) could actually reveal that SIGTTOU had been sent to the less process.




  • https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html



This is similar to SIGTTIN, but is generated when a process in a background job attempts to write to the terminal or set its modes. ...snip...




And apparently timeout(1) by default puts the process under management into background:




  • https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html



--foreground



Don’t create a separate background program group, so that the managed command can use the foreground TTY normally. ...snip...




So the solution to my problem was



$ PAGER='/bin/timeout --foreground 12h /bin/less' man man


(and something equivalent in my wrapper)






share|improve this answer














Answering to my own question, as I couldn't really find any hints on this via my googling.



strace(1) could actually reveal that SIGTTOU had been sent to the less process.




  • https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html



This is similar to SIGTTIN, but is generated when a process in a background job attempts to write to the terminal or set its modes. ...snip...




And apparently timeout(1) by default puts the process under management into background:




  • https://www.gnu.org/software/coreutils/manual/html_node/timeout-invocation.html



--foreground



Don’t create a separate background program group, so that the managed command can use the foreground TTY normally. ...snip...




So the solution to my problem was



$ PAGER='/bin/timeout --foreground 12h /bin/less' man man


(and something equivalent in my wrapper)







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









nodakainodakai

247110




247110












  • Hmmm... I wonder it seemed to be working on my system then?
    – Kusalananda
    2 days ago






  • 1




    @Kusalananda /usr/bin/man is a completely different beast on OpenBSD than on linux, especially since they got rid of groff.
    – mosvy
    2 days ago






  • 1




    less still doesn't work right with timeout; when killed by a signal, less will fail to restore the stty/termios settings, and you will be left with having to do a blind reset or stty sane; try timeout 2s less ~/.bashrc.
    – mosvy
    2 days ago






  • 1




    @mosvy this (minimal example) wrapper seems to fix it for me g=$(stty -g); timeout 2s less ~/.bashrc || stty "$g"
    – roaima
    2 days ago












  • Nodakai, on my Debian version of timeout the man page and effect appear to contradict the GNU info page you referenced. With timeout 12h less the page works as I would expect - until the timeout gets reached. Specifically, the --foreground option is not required unless timeout itself is not being run directly from a terminal.
    – roaima
    2 days ago




















  • Hmmm... I wonder it seemed to be working on my system then?
    – Kusalananda
    2 days ago






  • 1




    @Kusalananda /usr/bin/man is a completely different beast on OpenBSD than on linux, especially since they got rid of groff.
    – mosvy
    2 days ago






  • 1




    less still doesn't work right with timeout; when killed by a signal, less will fail to restore the stty/termios settings, and you will be left with having to do a blind reset or stty sane; try timeout 2s less ~/.bashrc.
    – mosvy
    2 days ago






  • 1




    @mosvy this (minimal example) wrapper seems to fix it for me g=$(stty -g); timeout 2s less ~/.bashrc || stty "$g"
    – roaima
    2 days ago












  • Nodakai, on my Debian version of timeout the man page and effect appear to contradict the GNU info page you referenced. With timeout 12h less the page works as I would expect - until the timeout gets reached. Specifically, the --foreground option is not required unless timeout itself is not being run directly from a terminal.
    – roaima
    2 days ago


















Hmmm... I wonder it seemed to be working on my system then?
– Kusalananda
2 days ago




Hmmm... I wonder it seemed to be working on my system then?
– Kusalananda
2 days ago




1




1




@Kusalananda /usr/bin/man is a completely different beast on OpenBSD than on linux, especially since they got rid of groff.
– mosvy
2 days ago




@Kusalananda /usr/bin/man is a completely different beast on OpenBSD than on linux, especially since they got rid of groff.
– mosvy
2 days ago




1




1




less still doesn't work right with timeout; when killed by a signal, less will fail to restore the stty/termios settings, and you will be left with having to do a blind reset or stty sane; try timeout 2s less ~/.bashrc.
– mosvy
2 days ago




less still doesn't work right with timeout; when killed by a signal, less will fail to restore the stty/termios settings, and you will be left with having to do a blind reset or stty sane; try timeout 2s less ~/.bashrc.
– mosvy
2 days ago




1




1




@mosvy this (minimal example) wrapper seems to fix it for me g=$(stty -g); timeout 2s less ~/.bashrc || stty "$g"
– roaima
2 days ago






@mosvy this (minimal example) wrapper seems to fix it for me g=$(stty -g); timeout 2s less ~/.bashrc || stty "$g"
– roaima
2 days ago














Nodakai, on my Debian version of timeout the man page and effect appear to contradict the GNU info page you referenced. With timeout 12h less the page works as I would expect - until the timeout gets reached. Specifically, the --foreground option is not required unless timeout itself is not being run directly from a terminal.
– roaima
2 days ago






Nodakai, on my Debian version of timeout the man page and effect appear to contradict the GNU info page you referenced. With timeout 12h less the page works as I would expect - until the timeout gets reached. Specifically, the --foreground option is not required unless timeout itself is not being run directly from a terminal.
– roaima
2 days ago




















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492941%2fcoreutils-timeout1-plays-badly-with-man-less%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to make a Squid Proxy server?

第一次世界大戦

Touch on Surface Book