Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.os.linux.misc    |    Linux-specific topics not covered by oth    |    135,536 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 134,681 of 135,536    |
|    Nuno Silva to rbowman    |
|    Re: Ridiculous Online Programming "Advic    |
|    11 Jan 26 23:57:22    |
   
   From: nunojsilva@invalid.invalid   
      
   On 2026-01-11, rbowman wrote:   
      
   > On Sun, 11 Jan 2026 10:32:08 +0000, Nuno Silva wrote:   
   >   
   >> These two produce an off-by-one, right?   
   >   
   > The bash version does since it also counts 'grep --color=auto watchdogd'   
   > along with the watchdogd process itself.   
      
   Yeah, and just that one. The other is, of course, not affected because   
   it doesn't invoke grep.   
      
   (I wish I could go one week without a post where lack of coffee leads to   
   some sort of mistake...)   
      
   > improved version:   
   >   
   > AmRunning() {   
   > ps aux | grep -v "grep" | grep $1 | wc -l   
   > }   
      
   Would it be preferrable to just subtract one?   
      
   I think another approach is to add [ and ] around one letter of what   
   you're filtering for, but that'd require modifying the string, and   
   shares one issue with "grep -v grep": it doesn't work as intended if the   
   name you are grepping for is grep.   
      
   (But then we also have to consider words being something other than   
   argv[0]. 'ps axo comm', perhaps?; Is that 'ps -eo comm' in POSIX   
   syntax?)   
      
   > $ AmRunning firefox   
   > 11   
   >   
   > That was an unexpected result since Firefox wasn't running. Further   
   > investigation revealed Tor was showing its roots   
   >   
   > tor-browser/Browser/firefox.real   
   >   
   > Kill Tor and   
   >   
   > $ AmRunning firefox   
   > 0   
   >   
   >   
   >   
      
   --   
   Nuno Silva   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca