title: How can I print the runtime stack trace of a Ruby 1.9 process?
body: <p>Is there any way to print the runtime stack trace of a Ruby 1.9.x process? I know that there was a utility called <code>pstack</code> for Ruby 1.8, but the project appears to have been abandoned a couple years ago: <a href="https://github.com/ice799/pstack">https://github.com/ice799/pstack</a>. Does anything like this exist for Ruby 1.9? Thanks a lot!</p>
  
  <p>EDIT: I'm interested in using an external tool to generate the stack trace (not running in the same memory space as the Ruby process).</p>
  
  <p>As @mosch pointed out, the <code>Kernal#caller</code> method works from within the running Ruby process.</p>
  
  <p>You could even build in support to your Ruby code that traps process signals and prints a stack trace:</p>
  
  <pre><code>Signal.trap("SIGTERM") { p caller }
  </code></pre>
  
  <p>Reference: <a href="http://www.ruby-doc.org/core-1.9.3/Signal.html">http://www.ruby-doc.org/core-1.9.3/Signal.html</a> </p>
  
  <p>I could build this functionality into my code, but I'd prefer to use a more generalized, external solution. Thanks.</p>