Posts

Showing posts from 2015

Distroshare Ubuntu Imager - Remastersys replacement

I have been Remastersys to backup my customized distros for what seems like years. Its been a wonderful utility nicely tailored for this task. But its development stopped few years back, and so there have been couple of alternatives for that. Just recently I had to put together an ISO of my current OS setup on one of my laptops. So digging around I stumbled upon distroshare utility. This is a nice replacement for Remastersys. Its actually called Distroshare Ubuntu Imager. After trying it out I found that it does exactly what I was looking for. And I successfully created a Live CD backup using distroshare.

TCP/IP Client server persistent connections

So just last week I was moved to another project where I'm gonna be working on a client server program. So we are going to be using TCP/IP for communication. And its exciting since its been over two years since I last dabbled in networking. Life is looking exciting. Anyway so the problem was everywhere I looked, I could find only simple networking examples. So I dug in and put together some code to keep a connection alive for back and forth connection. What I did was basically keep the connection open for next request rather than closing it and reopening it. This enabled me to have a continuous chat like communication between client and server. Then I spent some time refactoring the code to make it streamlined. But I still have to add error handling to it. I'll share it here when I have it ready. It was fun!!!

Limiting CPU percentage of a process

cpulimit is a utility available on Linux to limit the CPU time of any process. The use is cpulimit -l [℅ CPU] -e [binary name] I found it useful to emulate slow embedded processor behavior on desktop.

Qt Object Thread Affinity

Image
Example code: https://drive.google.com/file/d/0BxorjNRCBW61ZEJhaEJST1RZa0k/view?usp=sharing For last whole year I have been totally lost between threads, mutexes, shared data, pointers, signals and slots and blah blah blah. Actually I have learned a heck of lot about all these things in these few months. But I think I haven't grasped everything yet. There are many combinations that I don't know work or not. And I think there are many other tricks I am yet to learn especially when it comes to debugging. Anyway, this post is about QThread and object affinity. Well, the typical QThread example is way too simple. They show an object containing one worker function and that worker function running in that thread when they start the thread. Beyond that, nothing! What happens if you call any function on that object, what happens? What about concurrency? What about when the thread is busy? Will the slots get queued up? Lots and lots of questions. But the r

sudo apt-get remove linux-image-3.13.0-4*

Image
*update: It worked!!! In a hurry to remove multiple old linux kernel versions from my system I popped in above command. After a while I came back to the terminal to find all my kernels were un-installed!!! :J Well, thankfully I noticed what has happened and right away reinstalled the latest one with this command: sudo apt-get install linux-image-3.13.0-62-generic. Haven't rebooted yet. Let see!

Qt global thread pool max thread count

Recently I encountered that some threads are not launching in our application using QConcurrentRun. If you launched the same worker function over QThread it was working.   So digging into this gave us this problem with defaults for Qt's global threadpool. Basically Qt sets global threadpool's max thread count to the no of cores you have on your processor. We were easily running out of the default four max threads. So we upped the count to 32 using following function:  QThreadPool::globalInstance()->setMaxThreadCount(32); We set this at start of the program in main. Things have been fine since then!

Remove BOM (Byte-order mark) from a file

Image
Got this script from following page: http://thegreyblog.blogspot.in/2010/09/shell-script-to-find-and-remove-bom.html #!/bin/bash set -o nounset set -o errexit DELETE_ORIG=true DELETE_FLAG="" RECURSIVE=false PROCESSALLFILE=false PROCESSING_FILES=false PROCESSALLFILE_FLAG="" SED_EXEC=sed USE_EXT=false FILE_EXT="" TMP_CMD="mktemp" TMP_OPTS="--tmpdir=" XDEV="" ISDARWIN=false if [ $(uname) == "SunOS" ] ; then   if [ -x /usr/gnu/bin/sed ] ; then     echo "Using GNU sed..."     SED_EXEC=/usr/gnu/bin/sed   fi   TMP_OPTS="-p " fi if [ $(uname) == "Darwin" ] ; then   TMP_OPTS="-t tmp"   SED_EXEC="perl -pe"   echo "Using perl..."   ISDARWIN=true fi function usage() {   echo "bom-remove [-adrx] [-s sed-name] [-e ext] files..."   echo ""   echo "  -a    Remove the BOM throughout the entire file.&q

Debug mode and release mode builds

Recently it just happened that the current product I'm working on had a crisis situation. What happened was testing found a number of inexplicable and inconsistent crashes in the product. We didn't have a debugger back then. So to fix these things, we got gdb compiled for target. Then couple more weeks went by in us trying to find the best way to debug the application. Ultimately we found that autogenerating core dumps for debug mode build is best solution. But as soon as we prepared debug mode build we found a number of other crashes in functionality that's properly working in release mode. To find out the reason, after numerous internet searches, we found there are some initialisation differences in debug mode n badly written code can cause it. So we went back n started fixing it. Now I was thinking about the RCA for this debacle. And I realised that we all were going in the opposite way at this. Basically everybody develops in debug mode and after codebase is stable

Viewing threads in top or ps

Image
  When we are dealing with multi threaded applications, we can use top or P's to see wayward threads. PS has -L option to view threads. Top has -H option to view threads. You can use top -n 1 command in to create a simple 'top' logging script.