CPULeash: A tool for capping per-process and process group CPU utilisation from userspace

It’s now mid October, there are 0 posts in 2017. Therefore I think it’s time to loosen up posting constraints and try make a bit more casual posts. For a start I will dig up one of the unfinished works. I will start with a quick overview of an old piece of tool (unmaintained) I wrote quite a few years ago. The tool caps the maximum CPU utilisation of a process from userspace without requiring root access. One instance of the process can cap multiple processes individually, in a group or it can also cap an entire process sub-tree. I intended to post about it in great detail, but this time I will keep it brief, and dig deeper in the next opportunity. Let’s get into it.

Motivation (from agony)

A few years ago, I was used to run different CPU intensive experiments on my old laptop, which would sometime run weeks. The CPU temperature used to go up to 95 Deg C. Sometimes it went upto 99 Deg C and then it used to throttle down the cores to get the temperature down. This is definitely not a healthy temperature, therefore I feared of hardware damage. The laptop had a metal case, which became so hot that it left red marks on my thighs. One time an entire chocolate bar melted into a pool of liquid chocolate (someone left it near the exhaust fan). Therefore it was time that I figure something out, such that I can run the experiments, but keep the laptop cool (relatively).

The obvious idea was to cap the CPU usage for the processes. An easy solution is to install a virtual machine and run the code inside the virtual environment. Note that, in my case nice does not work, as it does not help control how much of the CPU a processes utilises when it acquires it. I could have used cgroups, but I didn’t want to (I don’t know why). At that point of time I was feeling the need for Solaris Zones.

Essentially what I wanted is something portable in any *nix system, works completely from userspace and also does not need root privilege. Therefore I made a small tool which does in. It was written in C and POSIX compliant libraries.

Also note that, there is a similiar kind of tool called cpulimit, which I didn’t know existed when I wrote this. This tool works well too.

Given this situation, it was time to write something in-house … drum rollCPULeash.

Continue reading “CPULeash: A tool for capping per-process and process group CPU utilisation from userspace”

Advertisement

An overview of the PC Real Time Clock (RTC)

Introduction

Have you ever thought how the computer is able to display the correct time after you power on the system? There is a component called the RTC in the computer which stores this date and time information when the computer is turned off.

I will talk about how to read/write the date and time and use other features of the RTC using command-line tools, Linux RTC driver and also a low level direct access to the RTC internal registers.
Continue reading “An overview of the PC Real Time Clock (RTC)”

What are ID3 Tags all about?


id3_logo

When you play a music file in your favourite music player, or in your portable media player the track name, album, artist, lyrics gets displayed. You can search the songs with artists, album names. Even some of the tracks come with album art too, but there is no image file anywhere. The question generally arises, where does these information come from? The answer is straight forward; this metadata about the audio track is stored inside the audio file itself. The different audio files need different codecs. Different audio format files also have different such metadata systems. For example The Vorbis comments, APE tag, ID3 tags etc.

The most common and popular audio media (although not the best) is the mp3 . Mp3 audio format stores this metadata inside the music file, either at the beginning or at the end or at both locations. The music metadata system used with mp3 is called an ID3 Tag.
We will rip off the ID3 tag and check out what’s inside it in this article. We will discuss about ID3v1.x and ID3v2.x tags.

Continue reading “What are ID3 Tags all about?”

Beginners Guide to GCC

GCC is the default compiler in the GNU+Linux systems, and is used to compile small applications, big softwares, and the kernel. Often beginners are overwhelmed with the amount of information provided in the gcc manual. This tutorial highlights the most useful commands and describes how to use them, how to read warnings and errors from the compiler output and compile the C Language sourcecodes with gcc. This tutorial does not cover advanced options and topics, in depth details are avoided. This tutorial will give the basic idea, and after reading this i hope that the manual pages would be easier to read.

Continue reading “Beginners Guide to GCC”

Allegro 4.2.2

Introduction

Allegro Logo
Designing and programming games is anything but easy. One needs to understand the game logic (algorithm) and the graphics manipulation techniques, the core of the game, and good planning and synchronization between these, to design a game. And I don’t think anyone would debate the fact the graphics alone makes a huge impact on games. That means the core logic needs priority and concentration than the eye candy graphics.

To begin programming the games and their graphics we need to have the basic concepts of game programming clear, as well as a good graphics and I/O tool which does not drag a beginner into the complex world of syntaxes, datastructres, procedures, complex internals, etc. Thus, I’m sure everyone agrees that starting with OpenGL or DirectX programming becomes quite a job for beginners. So game making needs very good management and planning at first, then it needs coding knowledge, and a good programming tool or API is needed to complete the task smoothly. Selecting an API is very important, it should be simple and is usable and also powerful at the same time which will let you spend more time on the planning the game and code the techniques. Now all the properties are difficult to find.

In this article we will introduce you with a 2D and 3D game and graphics library called Allegro, primarily to be used with C Programming Language, which brings you a great platform to start game programming. Though you still will need to know the basic techniques and algorithms to design the core, but Allegro is a great API which takes a good care of the graphics, sound, I/O and all the other components. So you can do the core design with more concentration, and then create the multimedia components, and the I/O using Allegro with great simplicity. Allegro does this by hiding the complex internals with its simple abstract datastructres and similarly simple routines. And all this is not only for beginners, but this library also has the power inside for advanced and professional-level programming. Read the whole article to know about Allegro in details and jump start into allegro programming

Continue reading “Allegro 4.2.2”