ps?

Hi All,

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?

Many thanks,
-T
1
perl6
11/14/2020 2:02:34 AM
📁 perl.perl6.users
📃 1505 articles.
⭐ 0 followers.

💬 4 Replies
👁️‍🗨️ 14 Views

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.
1
curt
11/14/2020 2:26:31 AM
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" );
    }
0
perl6
11/14/2020 11:29:13 PM
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
0
roam
11/22/2020 11:50:19 PM
pgrep is sweet!
0
perl6
11/23/2020 5:45:55 AM
Reply:
(Thread closed)