Re: Finding the last foreground command in the current session
From:
Stephane Chazelas
Subject:
Re: Finding the last foreground command in the current session
Date:
Tue, 9 Jun 2015 22:26:08 +0100
User-agent:
Mutt/1.5.21 (2010-09-15)
2015-06-09 19:44:44 +0000, Debarshi Ray:
> Hey Stephane,
>
> On Fri, May 22, 2015 at 02:38:31PM +0100, Stephane Chazelas wrote:
> > Can you not just do a tcgetpgrp() periodically
>
> If by "periodically" you mean "polling", then no, I don't want to do
> that. I know a few terminal emulators do that, but it is bad for
> power consumption and battery life.
>
> (We already use tcgetpgrp for checking if there is a foreground
> process when the user clicks the 'x' buton.)
just a few thoughts
If it's for human interaction then 1/10s resolution is more than
enough and tcgetpgrp is just one system call. You could always
do it upon a specific escape sequence sent by PS1 (if you were
going to rely on the bash-specific PROMPT_COMMAND anyway), or
stop doing it 1/2 second after the last user input or pty
activity if you want to avoid it when the terminal is idle.
--
Stephane