Monday 9 April 2012

Automatically kill process using too much memory (Skype for Linux)


Recently i've found Skype 2.2 beta for Linux has been infrequently succumbing to massive memory leaks. Most of the time it will perform fine, however it will very occasionally manage to hose the entire system with horrific swapping and make everything unresponsive.

With no updates seeming to be forthcoming from Skype these days, a workaround seemed necessary. The solution being in the form of a clever perl script called Timeout being used to launch Skype.

Download the tarball (or zip) from the github repository and extract it somewhere appropriate:

tar -xvf nameofarchive
Navigate to the directory you've just extracted and make the script executable
chmod 777 timeout
Then you can use it to launch skype thusly
 ./timeout -m 1000000 skype 
Where -m tells it to watch the memory consumption, and is followed by the memory limit you wish to set in kilobytes. Here I set it to kill skype if it uses more than one gigabyte of memory.

To launch Skype like this all the time, use a program like Alacarte (Main Menu Editor) to change the command the Skype menu entry launches with to the path of the script. It should look something like:
/home/username/scripts/timeoutdir/timeout -m 1000000 skype
After running like this for a while I found that the script was using more cpu time than seemed reasonable, as it was running ten times a second, so I modified it to run once every ten seconds instead, which removed it entirely from concern, both cpu and power consumption wise.

To do this you'll want to open the timout script itself in your favourite editor
gedit timeout
And find the line that says 'my $frequency = 10;'

Change this to look like 'my $frequency = 0.1;'

Save and exit.

Hopefully this makes life easier for anyone afflicted similarly. You can of course use this to monitor and limit any process with regards to cpu or memory usage by utilising the timeout script to launch it.

No comments:

Post a Comment