Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PID of current rake task?

Tags:

shell

ruby

rake

I'm putting in a reaper line into a rake task to kill some additionally spawned ruby tasks as they somehow creep up on occasion.

system "ps aux | grep 'namespace:taskname' | grep ruby | grep -v grep | awk '{print $2}' | xargs kill -9; echo 'Reaped old namespace:taskname processes.'"

I'd like to add grep -v $PID_OF_CURRENT_TASK in that just to be sure I don't kill the current task that's running as well.

How do I get that PID?

like image 570
ylluminate Avatar asked Mar 01 '12 00:03

ylluminate


1 Answers

You get the current PID in Ruby with Process.pid

like image 54
Linuxios Avatar answered Oct 04 '22 04:10

Linuxios