Pages

Thursday, February 9, 2012

Some of the pics I have taken

Well I am not a professional photographer. Not even close to a good photographer. But I am going to share some pics I have taken. All the copyrights for this pics belongs to me alone.

After all Joy of happiness is in sharing it.

A cool evening, empty road and miles ahead left to explore...

Flow of a river...






Saturday, March 19, 2011

Tricky, generic function pointer

#include
/* This is our generic function pointer */
typedef void (*fp)(void);
int func1(int a)
{
printf("Inside Func 1. Received %d\n", a);
return 2;
}

char func2(char b)
{
printf("Inside Func 2. Received %c\n", b);
return 'b';
}

int main()
{
fp ptr1;
int temp1;
char temp2;

ptr1 = (fp) func1;

temp1 = ((int (*)(int)) ptr1)(1);
ptr1 = (fp) func2;
// ptr1('g');
temp2 = ((char (*)(char))ptr1)('a');
printf("Inside Main. Received %d %c\n", temp1, temp2);
return 0;
}

Passing a function pointer to a function

#include

int any_function(int(*pfun)(int, int), int x, int y){
return pfun(x, y);
}

int sum(int x, int y){
return x + y;
}

int product(int x, int y){
return x * y;
}

int difference(int x, int y){
return x - y;
}

int main(void){
int a = 10;
int b = 5;
int result = 0;
int (*pf)(int, int) = sum; /* Pointer to sum function */

result = any_function(pf, a, b);
printf("\nresult = %d", result );

result = any_function(product,a, b);
printf("\nresult = %d", result );

printf("\nresult = %d\n", any_function(difference, a, b));
return 0;
}

Simple function pointer in C

#include

int sum(int x, int y){

return x + y;

}

int product(int x, int y){

return x * y;

}

int difference(int x, int y){

return x - y;

}

int main(void){

int a = 10;

int b = 5;

int result = 0;

int (*pfun[3])(int, int); /* Function pointer array declaration */


/* Initialize pointers */

pfun[0] = sum;

pfun[1] = product;

pfun[2] = difference;


/* Call all three functions through pointers in an expression */

result = pfun[1](pfun[0](a, b), pfun[2](a, b));

printf("\n\nThe product of the sum and the difference = %d\n", result);

return 0;

}


Some string manipulations is shell script

var="hai hello world tom"

pattern output
echo ${var%%hello*} //hai
echo ${var%%tom} //hai hello world
echo ${var##*hello} //world tom
echo ${var##hello*} //hai hello world tom
echo ${#var} // 19

Some shell script Experiments

1. Capture Ctrl+c Signal using Shell script

trap 'echo pressed c' 2

read f


2. Getting current PID using shell script

#!/bin/sh

echo $$

3. Use of arrays in shell script

newmap['name']="Abc"

newmap['designation']="SSE"

newmap['company']="xyz"


echo ${newmap['company']}

echo ${newmap['name']}

echo "after"

newmap=(Abd SSE HRD)

echo ${newmap[0]}

echo ${newmap[1]}

echo ${newmap[2]}

for i in newmap

do

echo $i

done

Saturday, August 7, 2010

Linux Commands

I am posting some Linux commands which might be use full for others

Create RAID on Linux

mdadm --create /dev/md0 –level=5 –raid-devices=3 /dev/sdb /dev/sdc /dev/sdd

show raid details

mdadm –- detail /dev/md0

Stop raid

mdadm –-stop /dev/md0

Remove raid

mdadm –-remove /dev/md0


Installing RPM

rpm –ivh blahblah.rpm


Upgrading rpm

rpm –uvh blahblah.rpm


Removing RPM

rpm –ev blahblah.rpm


Creating rpms


compile driver
rename blahblah_(uname –a)
tar –cvzf blahblah_prebuild.tgz blahblah_(uname –a)
rpmbuild –bb ‘target=i386’ abc.spec

To extract rpm

rpm2cpio any.rpm cpio -idv

To load usb modules

modprobe usb-storage
modprobe oxci_hcd
modprobe ehc_hcd


Search contents of the file in current folder recursively

find . xargs grep –n
  
Turning on hibernation in windows from command prompt

powercfg –h on


Compiling Linux source

make mrproper
make clean

make menuconfig

make all && make modules && make modules_install && make install

How to Applying patch

patch p1 < abc.patch

cd back up

cpio –icuvd < /dev/st0

To find current partition

df

Generate ctags

ctags –R .

To see the version of a module

modinfo –F version

Enabling scsi logs

sysctl -w dev.scsi.logging_level=0xffffffff


To see change log of a Linux source rpm

rpm -q --changelog -p kernel......rpm less


Creating tar

tar –cvzf abc.tar *

Uncompress tar

tar –xvzf abc.*

Checking Kernel Version

uname –a

64 bit or 32 bit

uname -m

To see os version

cat /etc/SuSE-release in sles

cat /etc/redhat-release in RHEL