Using system is a question of economy here. With the backticks, you capture the command's output - only to throw it away. The system(LIST) form also avoids invoking the shell. Actually, if you were interpolating user input into the call, avoiding the shell via system(LIST) increases security as well, because you don't have to worry about shell metacharacters, but that's not the case here.

The benefit of storing the output from ps is twofold. First of all, you only need to call the program once, as opposed to twice. And then you can use Perl's own grep to search that data - as opposed to spawning a process for the grep binary, twice. What grep really returns is a list of all the list that matched, but we're not storing it. Using a list in an if condition simply checks if the list is empty or not, and that's what we do here.

Btw, have another look at the post. The first time around, I forgot another detail: I wasn't checking for whether the system calls succeed. Stupid omission now fixed..

Makeshifts last the longest.


In reply to Re^3: Why won't it die?? by Aristotle
in thread Why won't it die?? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.