Tuesday, January 24, 2012

Understanding :(){ :|:& };: fork() bomb code

gets called recursively (recursive function). This is most horrible code for any Unix / Linux box. It is often used by sys admin to test user processes limitations (Linux process limits can be configured via /etc/security/limits.conf and PAM).

Once a successful fork bomb has been activated in a system it may not be possible to resume normal operation without rebooting, as the only solution to a fork bomb is to destroy all instances of it.

:() - It is a function name. It accepts no arguments at all. Generally, bash function is defined as follows:

foo(){  arg1=$1  echo ''  #do_something on $arg argument }

fork() bomb is defined as follows:

:(){  :|:& };:

:|: - Next it call itself using programming technique called recursion and pipes the output to another call of the function ':'. The worst part is function get called two times to bomb your system.

& - Puts the function call in the background so child cannot die at all and start eating system resources.

; - Terminate the function definition

: - Call (run) the function aka set the fork() bomb.

Here is more human readable code:

bomb() {  bomb | bomb & }; bomb

Properly configured Linux / UNIX box should not go down when fork() bomb sets off.

Saturday, January 21, 2012

Friday, January 20, 2012

Virtual Memory in Linux Kernel

http://www.informit.com/articles/article.aspx?p=29961

Garbage Collector - concepts

http://blogs.msdn.com/b/abhinaba/archive/2009/01/25/back-to-basic-series-on-dynamic-memory-management.aspx

rms, classic geek!

The Most Excellent and Lamentable Tragedy of Richard Stallman


http://edward.oconnor.cx/2005/04/rms

GCC guide

http://www.network-theory.co.uk/docs/gccintro/index.html
Must See Chapters 5,6,10,11,12,13

Thursday, January 19, 2012

link for linux system tools

http://lcamtuf.coredump.cx/fenris/other.txt

CS Grads not really trained

really worth reading...
morden frameworks and tools....spoil the students(CS Grads)

http://itmanagement.earthweb.com/article.php/3761921
http://www.crosstalkonline.org/storage/issue-archives/2008/200801/200801-Dewar.pdf

A professional embedded systems software engineer requires specific knowledge in a number of areas, together with problem-solving skills to apply this knowledge as a team member in building safe, secure, and reliable systems. Regrettably, says Adacore’s Robert Dewar, emeritus professor at New York University, the educational approach typically seen in university Computer Science programs, especially in the U.S., fails to provide either. Changes in course content and focus are needed.
 
http://www.eetimes.com/design/embedded/4238223/The-education-of-embedded-systems-software-engineers--failures-and-fixes?pageNumber=0

here is something against WEB
http://www.codinghorror.com/blog/2009/08/all-programming-is-web-programming.html

compilers - basic optimization

http://www.strchr.com/what_your_compiler_can_do_for_you

DSP Beginners Guide

http://eetimes.com/design/signal-processing-dsp/4017022/DSP-programmer-s-guide

Embedded Systems Kick start

http://en.wikibooks.org/wiki/Embedded_Systems

Most Programming Interviews are waste of time

http://teddziuba.com/2008/10/most-programming-interviews-ar.html

Why Software Suck

http://xahlee.org/UnixResource_dir/writ/why_software_suck.html

References are not Addresses

Pointers are strictly "more powerful" than references; anything you can do with references you can do with pointers, but not vice versa. I imagine that's why there are no references in C -- it's a deliberately austere and powerful language.
http://blogs.msdn.com/b/ericlippert/archive/2009/02/17/references-are-not-addresses.aspx

Gstreamer Plugin Development(Android)

A simple gst plugin can be developed from the below links

http://lca2007.linux.org.au/talk/272.html
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/pwg/html/part-building.html

once we are able to develop plugins for linux, we should also able to develop for android...
I managed to develop plugin for android by writing Android.mk and was able to see the boilerplate details... but still stuck up with my element registration with the plugin...
Tried to debug using remote gdb and found some memory access violation errors. Since I am using emulator... there are differences between the shared objects in emulator and in NDK.. so have to try in dev...

Wednesday, January 18, 2012

understanding virtual functions

http://jovechia.blogspot.com/2009/02/how-g-implement-virtual-function.html

using gdbserver on android emulator

1. Make your library debugable (add -g options in makefile)
modify your Android.mk add below command "LOCAL_CPPFLAGS += -g" for C++ files and "LOCAL_CFLAGS += -G" FOR C files.
rebuild your library and system image(if necessary)

2. in your local system redirect the debug port
$ telnet localhost 5554
redir add tcp:1234:1234
exit

3.you can start emulator by below command with debug port redirected.
./emulator -avd avdname -qemu -redir udp:1234::1234

4. push gdbserver to emulator
adb push ./out/target/product/generic/obj/EXECUTABLES/gdbserver_intermediates/gdbserver /system/bin/

5. run # gdbserver :1234 --attach your-desired-pid or gdbserver :1234 desired_process

6. run ./prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb ./out/target/product/generic/symbols/system/bin/app_process

7. in gdb-terminal
gdb>set solib-search-path out/target/product/generic/symbols/system/lib
In case there are multiple library paths to be searched, use ':' to concatenate the paths
gdb>target remote localhost:1234

8. Now you can see the Errors .... Happy remote Debugging!!!!

Common Error:

Malformed packet(b) (missing colon): re:0;
Packet: 'T050b:00000000;0d:c03ecebe;0f:b0070040;thread:4ab;core:0;'

This means the gdbserver and gdb in localhost are not compatible!!

Sunday, January 15, 2012

linux-android cross-compiling EGL surafce

Here is a simple HelloWorld EGL prog tat creates android window and displays openGL ES Surface
http://jiggawatt.org/badc0de/android/
(main.c)

Here is a Android.mk file for cross compiling this with NDK

LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE:=arm
LOCAL_MODULE:=mini
LOCAL_SRC_FILES:=main.c
LOCAL_MODULE_TAGS:=eng debug
LD_LIBRARY_PATH:=/home/shivram/android-ndk-r6b/platforms/android-14/arch-arm/usr/lib
LOCAL_LDLIBS:=\
-L/home/shivram/android-ndk-r6b/platforms/android-14/arch-arm/usr/lib \
-lEGL \
-ldl \
-lsurfaceflinger \

-lhardware \
-lhardware_legacy \
-lpixelflinger \

-lwpa_client \
-lemoji \
-lnetutils \
-ljpeg \
-lc \
-llog \
-lexpat \
-lskia \
-lui \
-lcutils \
-lutils \
-lbinder \
-lsurfaceflinger_client \
-lGLESv1_CM

LD:=/home/shivram/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
LOCAL_SHARED_LIBRARIES:=\
EGL \
GLESv1_CM
LOCAL_CFLAGS := \
-DHAVE_CONFIG_H \
-I/home/shivram/android-ndk-r6b/platforms/android-14/arch-arm/usr/include \
-I/home/shivram/android-ndk-r6b/platforms/android-14/arch-arm/usr/include/EGL \
-I/home/shivram/android-ndk-r6b/platforms/android-14/arch-arm/usr/include/GLES \
-DG_THREADS_MANDATORY \
-DG_DISABLE_DEPRECATED \
-Wall \

-Wdeclaration-after-statement \
-Wvla \
-Wpointer-arith \
-Wmissing-declarations \
-Wmissing-prototypes \
-Wredundant-decls \
-Wundef \
-Wwrite-strings \
-Wformat-nonliteral \
-Wformat-security \
-Wold-style-definition \
-Winit-self \
-Wmissing-include-dirs \
-Waddress \
-Waggregate-return \

-Wno-multichar \
-Wnested-externs \
-g \
-nostdlib \
-Bdynamic \
-Wl,-dynamic-linker,/system/bin/linker \
-Wl,--gc-sections \
-Wl,-z,nocopyreloc \
-DGST_DISABLE_DEPRECATED

include $(BUILD_EXECUTABLE)

When we try to compile this.. we get... undefined reference to some pthread functions

To resolve this, the key is to write a wrapper or define those missing functions in ur (main.c) code ;)

Friday, January 13, 2012

Building GStreamer for Android

http://gstreamer.freedesktop.org/wiki/GstreamerAndroid_InstallInstructions

1)Best use NDKr6b(copy the platform[android-14])
2) ICS-src/bionic/linker/linker.c --> SO_MAX 128 --> +62 needed --> Maximum number of shared objects tat can be loaded at a time should be increased and Android Src must be recompiled
3)GST_REGISTRY_UPDATE=yes
4)GST_REGISTRY=/data/data/com.android.freedesktop.gstreamer/cache/registry.bin
5)GST_PLUGIN_PATH=/data/data/com.android.freedesktop.gstreamer/lib
6)GST_PLUGIN_SCANNER=/data/data/com.android.freedesktop.gstreamer/bin/gst-plugin-scanner
7) Better Copy the bins in the application to /system/bin/ with 777 permissions

After Building GST for ICS(android-14), I was able to play audio files on the device and also tried to ndk-build with proper JNI[Key: LDFLAGS:=-lX --> means load libX.so from LD_LIBRARY_PATH].....then I realised that there is no proper video sink for android in GST as it uses X-Overlay. so.....

https://wiki.linaro.org/WorkingGroups/Middleware/Multimedia/Specs/1105/GstreamerEglSink

Android NDK Build - Tutorial

http://marakana.com/forums/android/examples/49.html
http://earlence.blogspot.com/2009/07/writing-applications-using-android-ndk.html

Running a (*.o) Exec in Android Shell

http://jiggawatt.org/badc0de/android/

Thursday, January 12, 2012

Linux Kernel Bootup Process

http://www.ibm.com/developerworks/library/l-linuxboot/index.html
http://free-7.blogspot.com/2010/10/linux-boot-process.html

Linux Kernel Doc - Help

http://whatisthekernel.blogspot.com/
http://www.kernel.org/doc/
http://web.dit.upm.es/~jmseyas/linux/kernel/hackers-docs.html
http://www.nondot.org/sabre/os/articles
http://kernelnewbies.org/Documents/Kernel-Docbooks

Wednesday, January 11, 2012

Reset Linux passwd ~ by booting in Single User Mode


You can enter single user mode directly after turning on the power to your system. The steps to do this are listed below.

1. Power on your system. Wait for the "Grub loading" message to appear and, depending on your Linux distribution, get ready to hit either any key or the ESC key to enter the grub boot menu.

Grub loading, please wait ... Press ESC to enter the menu 

or

Grub loading, please wait ... Press any key to enter the menu 

2. You will then get grub's main menu which will display a list of available kernels. Use the arrow keys to scroll to your desired version of the kernel and then press e for "edit".

Fedora Core (2.6.18-1.2239.fc5smp) Fedora Core (2.6.18-1.2200.fc5smp) 

3. The kernel's boot menu will appear. Use the arrow keys to scroll to the "kernel" line and then press e for "edit".

root (hd0,0) kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ initrd /initrd-2.6.18-1.2239.fc5smp.img 

4. A grub edit prompt will appear. Use the arrow keys to move to the end of the line and add the word "single" to the end, separated by a space. Change

grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ 

to

grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ single 

5. Press enter to save your changes, and then b for "boot".

6. The system will continue to boot, but will go straight to the root # prompt without first asking for a username and password and now we can reset any passwd.

Basic Linux Hello World Kernel module

Step 1: vi hello.c


#include
#include
#include

static int hello_init(void)
{
printk(KERN_ALERT "Hello World");
return 0;
}

static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye World");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL v2");
MODULE_AUTHOR(RICHIE);


Step 2: vi Makefile

obj-m := hello-kernel.o
hello-kernel-objs := hello.o

Step 3: make -C /lib/modules/`uname -r`/build M=`pwd`
You should see hello-kernel.ko in your current directory, by now.

Step 4: sudo /sbin/insmod hello-kernel.ko

Step 5: dmesg

You should see "Hello World" here.

Step 6: lsmod | grep hello-kernel

Step 7: modinfo hello-kernel.ko

Step 8: sudo /sbin/rmmod hello-kernel.ko

Step 9: dmesg

You should see "Goodbye World" here.

how linux kernel works - Programmers' view

http://www.tuxradar.com/content/how-linux-kernel-works

geeksforgeeks - A Computer Science Portal

A Computer Science Portal
http://www.geeksforgeeks.org/

Gr8 db for C/C++ Interview qs!
http://www.geeksforgeeks.org/archives/category/linked-list
http://www.geeksforgeeks.org/archives/category/c-puzzles
http://www.geeksforgeeks.org/archives/category/gfact
http://www.geeksforgeeks.org/archives/category/tree
http://www.geeksforgeeks.org/archives/category/c-arrays
http://www.geeksforgeeks.org/archives/category/articles

Ankit's fav
http://dumpyard.tumblr.com/post/31130051/must-read-software-engineering-books

Humane Computing - The beginning of a new era

Man-Machine Interaction has constantly been evolving ever since machines were invented.It was computers that marked the beginning of an era where machines began to get smart and intelligent. Smarter machines facilitated better ways of communication and this ease of communication attracted even laymen towards them. As these machines evolved they began augmenting human intelligence to provide better and faster solutions to problems.

"The profound technologies are those that disappear"

Machines took up different shapes and forms of real world objects by encapsulating computing prowess within them. These objects have grown in dexterity to learn and understand human behavior. We are in an era where humans have become oblivious to the existence of these computing devices. Interaction among these ubiquitous computing devices provided a platform for setting up the pervasive environment.

The potential of these environments to understand human behavior has been aided by sensors through the advancement of several technologies facilitated by gesture recognition, haptic perceptions, acoustic and phonetic analysis etc. Soft computing techniques using an agglomeration of these inputs are able to react to human behavior by the use of actuators through technologies like iO2, audio synthesis, haptic simulators etc.

The pinnacle of Humane Computing will be a time where machines would be able to understand and react to human thoughts by analyzing neuron impulses in the human brain. At that juncture it will only be a matter of time before we humans loose our hold as the most dominant species on the planet.

Divya M
Shivram R V
Sudharsan C P
V M.Sc. SWE