Post crash debugging in Linux

- Enable core dump for your current session
chandra # ulimit -c unlimited

- Verify it is enabled
chandra # ulimit -c
unlimited

- Once you have a crash while running executable, check for core dump file.
chandra # ls -al core*
-rw——- 1 root root 50966528 Mar 26 14:57 core.7812

- Open your executable in kdbg. Then, import core dump file from File -> Core Dump.

You will see where the exe crashed and all memory and local variable goodies.

Posted under Linux

This post was written by Chirag on April 19, 2009

Tutorials - C++/PHP etc

http://www.java2s.com/

Posted under General, Programming, c++

This post was written by Chirag on April 15, 2009

Asterisk 1.6.0.6 on Debian 4.0

- Check Linux kernel version
# uname -a
Linux ElectronWork 2.6.24-etchnhalf.1-686 #1 SMP Fri Dec 26 04:10:16 UTC 2008 i686 GNU/Linux

- Check Debian version
# cat /etc/debian_version
4.0

- Install various pre-requisite libraries.
# apt-get install make
# apt-get install gcc
# apt-get install g++
# apt-get install libc-dev
# apt-get install bison
# apt-get install ncurses-dev
# apt-get install libssl-dev
# apt-get install libnewt-dev
# apt-get install zlib1g-dev
# apt-get install initrd-tools
# apt-get install cvs
# apt-get install procps
# apt-get install doxygen

- Get Asterisk package.
# wget http://downloads.digium.com/pub/asterisk/releases/asterisk-1.6.0.6.tar.gz
# tar xvzf asterisk-1.6.0.6.tar.gz
# cd asterisk-1.6.0.6

- Install Asterisk
# ./configure
If you see asterisk symbol in the end, configuration is successful. Else, grep for “no” in config.log and try to install those missing libraries/utilities.
# make
takes ~11min
# make install
# make samples (optional)
# make progdocs (optional)

- Test your installation.
# asterisk -r

Posted under Asterisk, Infrastructure, Linux

This post was written by Chirag on March 2, 2009

Attributes of Objects

Attributes of Objects - Chirag Patel January 01, 2009

type
- Determines size of object and its memory address alignment
- the values the object can have
- the operations that can be performed on the object
- a function type specifies function parameter lists and return type

scope
- portion of translation unit (source code produced by preprocessor from source and header files) in which the name is visible
- file scope, block scope, function prototype scope, function scope
- C++ has namespace scope and class scope in addition

storage duration
- lifetime of the storage of object
- static, automatic or dynamic
- enumeration constants, functions, labels, types - do not have storage duration

linkage
- no linkage => entity can’t be referenced via name from anywhere else
- internal linkage => entity that can be referenced via name declared in the same scope or in other scopes of the same translation unit
- external linkage => in addition to capabilities similar to internal linkage, this can be referenced in other translation units

keywords: auto, extern, register, static - defines storage duration and/or linkage

Posted under c++

This post was written by Chirag on January 2, 2009

System language for Debian Linux

System language for Debian Linux - Chirag Patel December 30, 2008

I ran into a simple but typical issue.

I was installing Debian 4 (kernel 2.6) today using minimal boot image CD and out of curiocity I selected its installation language to Gujarati. All screens showed almost 90% of the content in Gujarati (incorrectly translated at many places though). I select “English -US” as my choice of language for system locales. But, after installation and reboot, all the user screens had weird characters on screen (I was expecting English). I kept looking for a way to change locales and did this:

- I opened root terminal.
- Entered following command:
chirag@work~# dpkg-reconfigure locales
- I selected “en-US-utf-8″ from the list shown.
- After OKing this and rebooting the system, I found characters known to me!

Posted under Infrastructure, Linux

This post was written by Chirag on December 31, 2008

Wordpress SQL hack

http://www.smashingmagazine.com/2008/12/18/8-useful-wordpress-sql-hacks/

Posted under MySql, Programming

This post was written by Chirag on December 28, 2008

PCI standard requirements

PCI standard requirements - compiled by Chirag Patel December 27, 2008

Payment Card Industry (PCI) requirements of Data Security Standard (DSS) include following basic compliances:

- Install and maintain firewall configuration to protect card holder data.
- Do not use vendor supplied defaults for system passwords and other secuirity parameters.
- Protect stored cardholder data.
- Encrypt transmission of cardholder data across open, public networks.
- Use and regularly update anti-virus software.
- Develop and maintain secure systems and applications.
- Restrict access to cardholder data by business need-to-know.
- Assign a unique ID to each person with computer access.
- Restrict physical access to cardholder data.
- Track and monitor all access to network resources and cardholder data.
- Regularly test security systems and processes.
- Maintain a policy that addresses information security.

(Ref: WEBSITE magazine November, 2008)

Posted under Infrastructure

This post was written by Chirag on December 28, 2008

Memory thrashing

Memory Thrashing - compiled by Chirag Patel December 27, 2008
(Ref: Embedded Systems Design June 2008)

Memory threshing is a typical problem that goes unnotices while programming time-critical systems. Translation Look-aside Buffers (TLB) are used for data and instruction cache. There are two main cache-replacement schemes: 1) Least Frequently Used (LFU) and 2) Least Recently Used (LRU). Memory accesses require address translations in modern systems. So, when a page table is is found in an on-chip TLB (a TLB hit), the lookup normally does not do translation. On TLB miss, the processor must look again and must calculate offset to find a byte physically.

When a system has multiple concurrent accesses, operating system schedules time slices for those processes. If we consider 32-entry LRU TLB and 6 processes each using different page memory, at least 12 pages are active at any given time (instruction + data). If every process uses double nested procedures (or jumps between 3 pages) in each time slice, there are 36 active pages. If operating system time slices sequentially, by the time 6th process is reached, 30 pages are accessed. By the end of 6th process time slice, 36 page accesses should have passed. So, the cache manager will discard first 4 accesses (LRU algorithm). When the time comes for the first process, it will have TLB misses for those first 4 page accesses. As the processor continues, it keeps discarding the pages that the next process in sequence will need. This memory thrashing greatly degrades system performance.

To avoid thrashing:
- Long unused variables should be declared absolutely rather than relatively.
- Macros should be expanded.
- Avoid nesting procedure calls whenever possible.
- Minimize number of concurrent tasks.
- Don’t use jumps larger than page size unless absolutely necessary.

Posted under Programming

This post was written by Chirag on December 28, 2008

Folding with VIM

Folding with VIM - Chirag Patel Dec 14, 2008

– Edit “~/.vimrc”

– Add following options
set fmr={,}
set fdm=indent

– To use syntax folding for a file, enter following command after opening it.
:set fdm=syntax

– To set no folding, edit “~/.vimrc”
set nofoldenable

– By default all available folds are folded. Change that to preferred max in “~/.vimrc”.
set fdn=1

1 is good value as it will close all top level folds to be closed (e.g. functions), but not any blocks inside.

– Some commands while in command in command mode:
zo ==> open fold under cursor
zO ==> open folds recursively under cursor
zc ==> close fold under cursor
zC ==> close folds recursively under cursor
zA ==> toggle folds recursively
zM ==> close all folds in a file
zR ==> open all folds in a file

Posted under Infrastructure, Linux

This post was written by Chirag on December 15, 2008

My VIM configuration

Vim Basic Configuration - Chirag Patel Dec 14, 2008

— Edit “~/.vimrc” file and add following tags per need

set autoindent ==> auto-indent code
set incsearch ==> start searching as we type word for search
set hlsearch ==> highlight all occurrences for search
set nowrap ==> disable line wrapping
set ts=4 ==> set tabsize to 4 space size
set softtabstop=4 ==> tabbing match my tabsize of 4
set shiftwidth=4 ==> shifting match my tabsize of 4
set noexpandtab ==> do not replace tab with spaces
set showmatch ==> highlight matching bracket/braces as we move cursor
set mat=5 ==> matching for search
set nocompatible ==> no vi compatibility
filetype on ==> vim detects file type
syntax on ==> highlight syntax words for file type
set ruler
set cindent ==> “C” indent rules for auto-indent
==> following command restores file position while re-opening
autocmd BufReadPost *
\ if expand(”:p:h”) !=? $TEMP |
\ if line(”‘\”") > 0 && line(”‘\”") following command postpones using “zv” until after reading the modelines
autocmd BufWinEnter *
\ if exists(”b:doopenfold”) |
\ unlet b:doopenfold |
\ exe “normal zv” |
\ endif

Posted under Infrastructure, Linux

This post was written by Chirag on December 15, 2008