title: Command line command to auto-kill a command after a certain amount of time
body: <p>I'd like to automatically kill a command after a certain amount of time.  I have in mind an interface like this:</p>
  
  <pre><code>% constrain 300 ./foo args
  </code></pre>
  
  <p>Which would run "./foo" with "args" but automatically kill it if it's still running after 5 minutes.</p>
  
  <p>It might be useful to generalize the idea to other constraints, such as autokilling a process if it uses too much memory.</p>
  
  <p>Are there any existing tools that do that, or has anyone written such a thing?</p>
  
  <p>ADDED: Jonathan's solution is precisely what I had in mind and it works like a charm on linux, but I can't get it to work on Mac OSX.  I got rid of the SIGRTMIN which lets it compile fine, but the signal just doesn't get sent to the child process.  Anyone know how to make this work on Mac?</p>
  
  <p>[Added: Note that an update is available from Jonathan that works on Mac and elsewhere.]</p>