title: Find out if a ruby script is currently running
body: <p>I have a ruby script that gets triggered every minute by a CRON job called 'process_files.rb'.</p>
  
  <p>process_files.rb executes another ruby script called 'process_client.rb' with paramaters like so:</p>
  
  <pre><code>ruby process_client.rb -c ABC -s 123 -f /path/to/client/file/client_file
  </code></pre>
  
  <p>Since process_files.rb runs every minute I want to avoid running process_client.rb if a version of it is currently running with same -c parameter. So if process_client.rb is currently running for -c ABC, it will not 
  execute the ruby command above. </p>
  
  <p>Both of the scripts are in the same directory called /cdir.</p>
  
  <p>This is what I've got in process_files.rb but it is not working:</p>
  
  <pre><code>client = "ABC"
  name = "process_client.rb -c #{client}"
  needle = `find /cdir -maxdepth 1 -type f -name #{name}`.to_i
  if needle &gt; 0
     puts "DONT RUN the ruby script for client abc"
  else
     puts "RUN the ruby script for client abc"
     ruby process_client.rb -c ABC -s 123 -f /path/to/client/file/client_file
  end
  </code></pre>
  
  <p>Then before I execute process.files.rb I execute process_client.rb for client ABC, which has some code to put it into sleep mode for 30 seconds, like so:</p>
  
  <pre><code>...some code
  sleep 30
  ...some code
  </code></pre>
  
  <p>The problem is that process_files.rb never finds the current execution of process_client.rb for client ABC and executes another version when it should not.</p>
  
  <p>Something is probably wrong with the <code>find</code> command but I don't know what it is.</p>