Re: pgrep -f 'foo' | wc -l -- curiousity!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Aug 09, 2017 at 02:06:20PM -0400, bruce wrote:
> Hey peeps.
> 
> From a fed/centos cmdline...
> 
>  pgrep -f "foo" | wc -l
> 
> will return 0 -- if "foo" doesn't exist in the procTBL, and something
> else if "foo" is running.
> 
> The curiousity... When I have a simple php
> 
> <?php
> 
> $f="pgrep -f 'foo' | wc -l";
> $t=`$f`;
> print $t
> 
> ?>
> 
> $t isn't 0!! -- it's actually 1, or something else if foo is running..
> 
> Any ideas why?? I've used the different methods php provides to "run"
> shell/.cmdline processes. I get the same results.
> 
> Now.. I can do something like
>  ps aux | grep 'foo' | grep -v 'grep' | wc -l
> and get the correct results within the php as well as the shell.
> 
> Didn't find anything via the 'net or SO on this..
> 
> Thoughts/comments??

The -f option to pgrep says to look at the command and it arguments.
If you are looking for a command NAMED "foo" and have another command
with "foo" as an argument, "pgrep -f" may list that as well.

Two alternatives, drop the "-f" to look at only the cmd name
or run your pgrep as "pgrep -f '[f]oo'".  That cmd line does
not contain "foo" but still searches for "foo".

jl
-- 
Jon H. LaBadie                  jonfu@xxxxxxxxxx
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux