How to get PID of current rake task?

RubyShellRake

Ruby Problem Overview


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?

Ruby Solutions


Solution 1 - Ruby

You get the current PID in Ruby with Process.pid

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionylluminateView Question on Stackoverflow
Solution 1 - RubyLinuxiosView Answer on Stackoverflow