Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Parsing this:</p> <pre><code>ps aux | grep [-i] $ProcessName | wc -l </code></pre> <p>...is probably your best bet. Here's a short script that does what you're after:</p> <pre><code>#!/bin/bash PROCESS=myapp number=$(ps aux | grep $PROCESS | wc -l) if [ $number -gt 0 ] then echo Running; fi </code></pre> <p><strong>EDIT:</strong> I initially included a <code>-i</code> flag to <code>grep</code> to make it case insensitive; I did this because the example program I tried was <code>python</code>, which on Mac OS X runs as <code>Python</code> -- if you know your application's case exactly, the <code>-i</code> is not necessary.</p> <p>The advantage of this approach is that it scales with you -- in the future, if you need to make sure, say, <em>five</em> instances of your application are running, you're already counting. The only caveat is if another application has your program's name in its command line, it might come up -- regular expressions to <code>grep</code> will resolve that issue, if you're crafty (and run into this).</p> <p>Research the Darwin man pages for <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/ps.1.html" rel="noreferrer"><code>ps</code></a>, <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/grep.1.html" rel="noreferrer"><code>grep</code></a>, and <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/wc.1.html" rel="noreferrer"><code>wc</code></a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload