Monologue on the tubes

Reduce CPU usage by putting unused programs to sleep

Last update 2015-03-02 19:43:44

Some weeks ago I started evaluating the Atom text editor, as a temporary replacement for my usual tools which are (micro)emacs and cscope (yes, I am just that metal)...

The "interesting" thing about Atom is that it is basically a web browser and the file you are editing is rendered as a web page. This allows development in "web languages", which supposedly makes it easier and accessible to more people. On the other hand, this also makes Atom a very heavy application - even compared to something like Eclipse. It also consumes a lot of CPU cycles even when you are not using it. On my desktop machines each idle instance of Atom uses 10-30% of a core for god knows what reason.

At work, I normally open 1-2 editors per project and may leave them open on a dedicated screen for weeks before I go back to them. This is normally not a problem with microemacs or even full emacs but with Atom, my standard 8-9 editor windows would significantly slow down my machine. So I had to come up with a hack to make Atom use less power.

Sleep tight my little process...

If you send the STOP signal to a process, it will - wait for it - stop executing. You can make it resume by sending the CONT signal to it. It works like this:
# put it to sleep...
kill -s STOP pid

# wake it up!
kill -s CONT pid
So how does this help us with atom? Well, for one I can now put the ones I don't need to sleep. But more interestingly I can make them all stop eating CPU cycles, when I know I am not in the office, by adding the following lines to my cron:
# sleep atom at nights and re-wake it in the morning
30 20 * * 1-5 /usr/bin/killall -s STOP atom
30 7 * * 1-5 /usr/bin/killall -s CONT atom
There you have it, unix once again saves the environment...

Tags: hacks linux

<--Drum On, my little audio experiment

go back to front page or ride the tag cloud.