<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>I like Andy's PID file suggestion, but I would be inclined to
      make this a bash script rather than a perl one-liner and test
      something like:</p>
    <p>`ps aux | grep perl | grep starman`</p>
    <p><br>
    </p>
    <p>And if that command causes it's own failure (by always creating a
      process with 'perl' and 'starman') then:</p>
    <p>`ps aux | grep [p]erl | grep [s]tarman`</p>
    <p><br>
    </p>
    <p>If you find bash scripting not super easy (like me), ChatGPT is
      very helpful. It's helped me a lot in writing better admin
      scripts.<br>
    </p>
    <p><br>
    </p>
    <p>-Alan</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 11/25/24 9:41 AM, Andy Bach wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:SJ0PR09MB931920FE8E2A4CC76ADA5B16C02E2@SJ0PR09MB9319.namprd09.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
      <div class="elementToProof"
style="font-family: "Times New Roman", Times, serif; font-size: 11pt; color: rgb(0, 0, 0);">
        Need to expand your grep RE or add a grep -v to remove the ones
        you don't want, though, then you have to remove the one you just
        added.  Another is to track the pids, find the ones you've
        created and look for one outside that set.  You could have
        starman (if it doesn't) create a .pid file and use that to check
        that pid's status (with lsof -p <pid> maybe), rather than
        grepping.</div>
      <hr style="display:inline-block;width:98%" tabindex="-1">
      <div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif"
          style="font-size:11pt" color="#000000"><b>From:</b>
          Chicago-talk
          <a class="moz-txt-link-rfc2396E" href="mailto:chicago-talk-bounces+andy_bach=wiwb.uscourts.gov@pm.org"><chicago-talk-bounces+andy_bach=wiwb.uscourts.gov@pm.org></a>
          on behalf of Richard Reina <a class="moz-txt-link-rfc2396E" href="mailto:gatorreina@gmail.com"><gatorreina@gmail.com></a><br>
          <b>Sent:</b> Sunday, November 24, 2024 5:19 PM<br>
          <b>To:</b> Chicago.pm chatter <a class="moz-txt-link-rfc2396E" href="mailto:chicago-talk@pm.org"><chicago-talk@pm.org></a><br>
          <b>Subject:</b> [Chicago-talk] Determining if another perl
          process is running.</font>
        <div> </div>
      </div>
      <div>
        <style type="text/css">.x_tg
        {border-collapse:collapse;
        border-spacing:0}.x_tg td
        {border-color:black;
        border-style:none;
        border-width:1px;
        font-family:Arial,sans-serif;
        font-size:14px;
        overflow:hidden;
        padding:5px 5px;
        word-break:normal}.x_tg th
        {border-color:black;
        border-style:none;
        border-width:1px;
        font-family:Arial,sans-serif;
        font-size:14px;
        font-weight:normal;
        overflow:hidden;
        padding:2px 2px;
        word-break:normal}.x_tg .x_tg-94ls
        {background-color:#cb0000;
        border-color:inherit;
        text-align:left;
        vertical-align:top}.x_tg .x_tg-pzl3
        {background-color:#FFFF00;
        border-color:inherit;
        text-align:left;
        vertical-align:top}</style>
        <table class="x_tg">
          <thead>
            <tr>
              <th class="x_tg-pzl3"><b>CAUTION - EXTERNAL: <br>
                </b></th>
            </tr>
          </thead>
        </table>
        <br>
        <div>
          <div dir="ltr">Hello everyone,
            <div><br>
            </div>
            <div>So excited about the Winter Perl Conference that I just
              registered for that I thought I would rebuild my aged Perl
              Dancer2 website. I 've done so and deployed it on a
              Digital Ocean droplet but I've hit a snag in setting up a
              cron job to make sure starman is running. It seems my
              query into whether the process is running gets treated as
              evidence that the process IS running. <br>
            </div>
            <div><br>
            </div>
            <div>When I do:</div>
            <div><br>
            </div>
            <div>perl -e 'my $smstat = `ps -ef | grep starman`; unless
              ($smstat =~ /starman master/) {
              system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/<a
                href="http://starman.pl" moz-do-not-send="true">starman.pl</a>
              start &>> /home/starman/starman.log"); print
              localtime . " starting starman\n"; } else { print "Starman
              is already running\n\n\n $smstat\n" }';<br>
              <br>
            </div>
            <div>RESULTS IN:</div>
            <div><br>
            </div>
            <div>Starman is already running<br>
              <br>
              <br>
               starman   203805       1  0 Nov08 ?        00:00:00
              /lib/systemd/systemd --user<br>
              starman   203806  203805  0 Nov08 ?        00:00:00
              (sd-pam)<br>
              root      472040     385  0 Nov20 ?        00:00:00 sshd:
              starman [priv]<br>
              starman   472049  472040  0 Nov20 ?        00:00:01 sshd:
              starman@pts/0<br>
              starman   472050  472049  0 Nov20 pts/0    00:00:00 -bash<br>
              starman   544383  472050  0 23:11 pts/0    00:00:00 perl
              -e my $smstat = `ps -ef | grep starman`; unless ($smstat
              =~ /starman master/) {
              system("XDG_RUNTIME_DIR=/run/user/1001 exec /home/starman/<a
                href="http://starman.pl" moz-do-not-send="true">starman.pl</a>
              start &>> /home/starman/starman.log"); print
              localtime . " starting starman\n"; } else { print "Starman
              is already running\n\n\n $smstat\n" }<br>
              starman   544384  544383  0 23:11 pts/0    00:00:00 sh -c
              ps -ef | grep starman<br>
              starman   544385  544384  0 23:11 pts/0    00:00:00 ps -ef<br>
              starman   544386  544384  0 23:11 pts/0    00:00:00 grep
              starman<br>
            </div>
            <div><br>
            </div>
            <div>It always says it's running even if it is not
              apparently because it's seeing 'starman master/ in the
              perl script that is inquiring. </div>
            <div><br>
            </div>
            <div>Anyone know a good solution to avoid this so that I can
              determine whether my starman startup script is
              indeed running?</div>
            <div><br>
            </div>
          </div>
        </div>
        <style type="text/css">.x_tg
        {border-collapse:collapse;
        border-spacing:0}.x_tg td
        {border-color:black;
        border-style:none;
        border-width:1px;
        font-family:Arial,sans-serif;
        font-size:14px;
        overflow:hidden;
        padding:5px 5px;
        word-break:normal}.x_tg th
        {border-color:black;
        border-style:none;
        border-width:1px;
        font-family:Arial,sans-serif;
        font-size:14px;
        font-weight:normal;
        overflow:hidden;
        padding:2px 2px;
        word-break:normal}.x_tg .x_tg-94ls
        {background-color:#cb0000;
        border-color:inherit;
        text-align:left;
        vertical-align:top}.x_tg .x_tg-pzl3
        {background-color:#FFFF00;
        border-color:inherit;
        text-align:left;
        vertical-align:top}</style>
        <table class="x_tg">
          <thead>
            <tr>
              <th class="x_tg-pzl3"><b>CAUTION - EXTERNAL EMAIL:</b>
                This email originated outside the Judiciary. Exercise
                caution when opening attachments or clicking on links.
              </th>
            </tr>
          </thead>
        </table>
        <br>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre wrap="" class="moz-quote-pre">_______________________________________________
Chicago-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a>
<a class="moz-txt-link-freetext" href="https://mail.pm.org/mailman/listinfo/chicago-talk">https://mail.pm.org/mailman/listinfo/chicago-talk</a>
</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 

Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.

science + technology = better workers

<a class="moz-txt-link-freetext" href="https://talalg.com">https://talalg.com</a>


He who confuses political liberty with freedom and political equality
with similarity has never thought for five minutes about either.

-- Shaw, from "Maxims for Revolutionists"</pre>
  </body>
</html>