Change the ruby process name in top

后端 未结 7 817
渐次进展
渐次进展 2021-02-18 14:19

I would like to change the name of the ruby process that gets displayed in the linux/unix top command. I have tried the

$0=\'miname\'

approach

7条回答
  •  一整个雨季
    2021-02-18 14:52

    I had a similar problem, updated the technique from the Dave Thomas post a little by putting it in a rack middleware, rather than the before/after pattern.

    Put this in lib/rack/set_process_title.rb:

    # Set the process title to the URI being processed 
    #- useful for debugging slow requests or those that get stuck
    class Rack::SetProcessTitle
      def initialize(app)
        @app = app
      end
      def call(env)
        $0 = env['REQUEST_URI'][0..80]
    
        @status, @headers, @response = @app.call(env)
    
        $0 = env['REQUEST_URI'][0..80] + '*'
    
        [@status, @headers, @response]
      end
    end
    

    ... and this goes at the end of config/environment.rb:

    Rails.configuration.middleware.insert_after Rack::Lock, Rack::SetProcessTitle
    

    More words in the blog post: http://blog.actbluetech.com/2011/06/set-your-process-name-in-top-and-ps.html

提交回复
热议问题