Search code examples
ruby-on-rails-2

How to kill process in ruby on rails after a specific time (like 2 seconds)?


What I want to do is... I have used PAPERCLIP to upload the file in server. for this i have used some shell scripts. now i want that when user browses for a file and clicks on upload button then from that moment i want to record time. and if process is still going on and specified time (suppose 5 seconds) expired, i want to kill that process. Now please tell me how to accomplish it?

I m using Process.pid. but if i m using 2 client window to access the website. Both window r displaying same process id.

Can anybody tell me how to kill process in ruby on rails after a specific time (like 2 seconds)? In rails different user can access website from their browser. So i want to create seperate Process id for each user n want to kill it once the specified time expires. I think it can be done with stop watches to specify the time. And for sparate process id i can use thread concept.


Solution

  •     Each Passenger instance is a separate process and it has it's own PID. Killing processes from Ruby is really easy. We do this by executing following command:
    
        1
        Process.kill(signal, pid)
        We will use this method and try to kill Passenger processes gracefully (gracefully means that Passenger process will complete any request that it is performing right now and will shutdown). If this fails, we will send a TERM signal and kill it instantaneously.
    
        SIGUSR1 signal - shutdown gracefully
        TERM signal - kill it instantaneously
    ----------------
    For more details :
    http://dev.mensfeld.pl/2012/08/simple-rubyrails-passenger-memory-consumption-limit-monitoring/