C/C++
Stack of a Running Process in Unix/Linux
Jul 26th
The command pstack can be used to view the stack trace of a running process.
Let us select a running process.
[neo@techpulp ~]# ps -e | grep konqueror 22937 pts/5 00:00:17 konqueror
Run pstack command with PID of the process.
[neo@techpulp ~]# pstack 22937 22937: konqueror (No symbols found) 0x001fb402: ???? (89c6ed8, 2, bfa39b08, 3812df0, 89c6ed8, 3c21362) 0x0325074b: ???? (89c6ed8, 8a00908) 0x03250656: ???? (89c6ed8, 3c372ec) 0x03237a59: ???? (bfa39c20, bfa39d48, bfa39de8, bfa39d1c, 0, bfa39fb4) + 4c0 0x03bb1d0d: ???? (1, bfa3a094, bfa3a09c, 0, bfa3a094, 1) + 40 0x00248de6: ???? (80485ec, 1, bfa3a094, 8048600, 8048650, 21ff2d) + 405c5f78 [neo@techpulp ~]#
There is an alternate way to use gdb and attach More >
ELF Binary Optimization for size
Jul 26th
The following steps help in reducing the size of a Linux application ELF binary. These operations can be used for application binary as well as shared library.
Use compiler optimization flags
-Os (optimize for size)
-O2
While linking, try to use following options. But do not use ‘-s’ option for kernel modules.
# ld -r -s --discard-local --discard-all testApp.o -o testApp # ld -r -s --discard-local --discard-all testLib1.o testLib2.o -o testLib.so # ld -r --discard-local --discard-all testMod1.o testMod2.o -o testMod
Strip the binary including unnecessary sections
# strip --remove-section=.note --remove-section=.comment testApp # strip --remove-section=.note --remove-section=.comment testLib.so
Parse words in a string
Jul 26th
This function requires an array of character pointers words of size maxWords. Note that the input string line supplied to this function will be modified (precisely placing NULL termination character at each word boundary). Alternately the function can be modified to duplicate strings using strdup to avoid modification of input string line. This function returns the number of words parsed. The return value will never exceed maxWords.
int parseWords(char *line, char *words[], int maxWords)
{
char *p;
int wordCount;
p = line;
wordCount = 0;
while(wordCount < maxWords) {
while(*p && isblank(*p)) p++;
if(!p[0]) return wordCount;
words[wordCount] = p;
wordCount++;
while(*p && !isblank(*p)) p++; More > 

Recent Comments