Friday, March 27, 2009

Compiling a multithreaded program

Hi all,

If sample.c is our program consisting of code leveraging POSIX threads for multithreading on a Linux platform then the following command is used to compile the program.

gcc -o sample sample.c -lpthread


Finding out dependencies of an executable in Linux

Hi all,

ldd command is used to find out the dynamic dependencies of an executable in a Linux/Unix environment.


will list out all the dynamic libraries used by the executable.It is a great tool to find out the missing modules needed by the executable.


Debugging C,C++ programs on Linux Platform

HI all,

Generally everyone use gdb for debugging C,C++ programs in Linux. There is another tool called valgrind that is an amalgamation of a host of other tools for debugging.For examples memcheck which is used to debug memory related issues, helgrind which is used to debug multithreading programs. The tool is open source and packages exist for all distributions. Usage

valgrind --tool=

Though I must say that you have to read the documentation about the concerned tool to find out exactly what is the meaning of the messages generated by every tool otheriwse its difficult to comprehend the out genereated by the tool for your executable.


Note about pthread_exit

Hi all,

A little note about usage of pthread_exit() while using multithreading on a Linux platform. pthread_exit() is used to kill a process for which it is called but it doesn't release the resource held by the thread immedeatly, this leads to increase in the memory footprint when a thread is killed. To complete this process use pthread_join() or pthread_detach().