On Sat, Nov 14, 2020 at 03:29:13PM -0800, ToddAndMargo via perl6-users wrote:
> On 2020-11-13 18:26, Curt Tilmes wrote:
> > On Fri, Nov 13, 2020 at 9:03 PM ToddAndMargo via perl6-users
> > <perl6-us...@perl.org> wrote:
> > > Fedora 33
> > > 
> > > I know I can get this information from a system
> > > call to "ps", but is there a way to tell if a
> > > program in running from Raku?
> > 
> > Running ps is probably as good as anything, but in linux you could
> > always just poke around under /proc,
> > e.g. Loop over /proc/*/cmdline and look for it.
> > 
> 
> Follow up:
> 
>    $PsStr = qqx ( ps ax );
>    if $PsStr.contains( "gnucash" )  {
>       PrintGreen( "GnuCash is running\n\n" );
>    } else {
>       # qqx ( gnucash );
>       my $pA = Proc::Async.new( "/usr/bin/gnucash" );
>       $pA.start;
>       PrintGreen( "GnuCash started\n\n" );
>    }

If the reason you want to run ps is to check whether a specific program
is running, I would very strongly suggest using the pgrep utility and
checking its exit code. There are many advantages to using pgrep over
trying to parse the output of ps, except for the case when you invoke ps
with a very, very specific set of options and columns, but... that's
pretty much equivalent to running pgrep anyway ;)

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

Attachment: signature.asc
Description: PGP signature

  • ps? ToddAndMargo via perl6-users
    • Re: ps? Curt Tilmes
      • Re: ps? ToddAndMargo via perl6-users
        • Re: ps? Peter Pentchev
          • Re: ps? ToddAndMargo via perl6-users

Reply via email to