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. Follow

4 Replies
14 Views

Similar Articles

[PageSpeed] 26

On Fri, Nov 13, 2020 at 9:03 PM ToddAndMargo via perl6-users
<perl6-users@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.
1
curt
11/14/2020 2:26:31 AM
On 2020-11-13 18:26, Curt Tilmes wrote:
> On Fri, Nov 13, 2020 at 9:03 PM ToddAndMargo via perl6-users
> <perl6-users@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" );
    }
0
perl6
11/14/2020 11:29:13 PM
--zx4FCpZtqtKETZ7O
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Nov 14, 2020 at 03:29:13PM -0800, ToddAndMargo via perl6-users wrot=
e:
> On 2020-11-13 18:26, Curt Tilmes wrote:
> > On Fri, Nov 13, 2020 at 9:03 PM ToddAndMargo via perl6-users
> > <perl6-users@perl.org> wrote:
> > > Fedora 33
> > >=20
> > > 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?
> >=20
> > 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.
> >=20
>=20
> Follow up:
>=20
>    $PsStr =3D qqx ( ps ax );
>    if $PsStr.contains( "gnucash" )  {
>       PrintGreen( "GnuCash is running\n\n" );
>    } else {
>       # qqx ( gnucash );
>       my $pA =3D 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

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

--zx4FCpZtqtKETZ7O
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAl+6+TUACgkQZR7vsCUn
3xPe/w/9HMVLffH0J8YpJiQSE5IqSVtB87f6bhhKNISw8/b7SXpXO+5/kWC4e9jI
KJiY6T9bHYJUJlqI1Gc3jymOLLliJkqFiA417POMpKmqihqovf76z3mmuFqFMteN
x/c11itupCz/UeSLS2wQqFeGGSdB5Nob21ULHqMJgxHp52Q4cAoa2SF9Vvu8mKxb
PZM8ZJqRaIhdb35VxESqdPOQvtbax3lPS959qVX1Y2MRiG/DERUWsVqshsb/pUR3
3LAsRVNJsSmZjAW399YHFvZX3ULtXepPrGZvB2oT6z/1KpPHdQwYtWHXvAYgdzxa
Ri/9MD8d3wssfNrtz9bgOiYqw/yYoL2h5KOviduTr2jZOUZPYDLb7sGiK6tMIiPG
/xMeZtDZQoK2FMVfzqo1aUbSGwDwkjLFqSvJtUzNgY9xmPXEWyx1Zv7fQXy++bRQ
xJHH+2Kzx7cgqJ+JZ+qNNSaltNHCv7vEHiKau5m3SthuUbNlvFlId89mA1tD7Ba7
2mea9QWERRxKSbLMzZDNddhGAvHshX9qToNsrrYU/vJGRsQzTxH/SYQVAXtv4U0b
LMG5eD/TUNvG3xA5jOnR/FKbXc0NKSjNBgBkSmhja5YGH9KsSH6qcKGEcU7P/Yka
kmUXMuhWjJ/6K2a8RDxmBlRHCXW2L0W3aPvk8T+NeTDYqDLy2QY=
=RdFz
-----END PGP SIGNATURE-----

--zx4FCpZtqtKETZ7O--
0
roam
11/22/2020 11:50:19 PM
On 2020-11-22 15:50, Peter Pentchev wrote:
> 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-users@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
> 

pgrep is sweet!

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
11/23/2020 5:45:55 AM
Reply: