0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

kill process for memory leak

Last updated at Posted at 2020-08-03

top

rails batch

get process info that maybe leaked memory

pinfo=`ps aux --sort -rss| grep [r]uby | head -1 | tr -s ' ' | cut -d ' ' -f2,6`
echo $pinfo

compare and graceful kill

pid=`echo -n $pinfo | cut -d ' ' -f 1`
mem=`echo -n $pinfo | cut -d ' ' -f 2`

threshold=20000
if [ "$mem" -ge "$threshold" ];then 
    echo "Memory leaked!"; 
    kill -s USR1 $pid; 
fi

purge-memory-leak-process.sh

#!/bin/bash

# 200MiB
threshold=209715200

pinfo=`ps aux --sort -rss| grep [r]uby | head -1 | tr -s ' ' | cut -d ' ' -f2,6`
if test -z "$pinfo";then 
    echo "not found";
    exit; 
fi

pid=`echo -n $pinfo | cut -d ' ' -f 1`
mem=`echo -n $pinfo | cut -d ' ' -f 2`

if [ "$mem" -ge "$threshold" ];then 
    echo "[$pid]: Memory leaked!"; 
    kill -s USR1 $pid; 
fi
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?