India 2020

by A.P.J Abdul Kalam and Y.S Rajan

Author being X President of India and held various top positions, has envisioned India in 2020. Writing a vision document of a country is not possible for all who haven’t held so many different top positions in government.
As the title of the book indicates, book is a vision of India in 2020. Book was written quite few years back and reading it now is a kind of evaluation of, have we achieved our vision. Author has explained in detail about, other countries vision of 2020, envisioned where India should stand in 2020 and what kind investment and focus is required on various sector. Some of the sectors author has explained are, Food, Agriculture and processing, materials like steel, aluminium and titanium, chemical industries (petrochemicals, phamaceutical chemicals, agro chemicals, textiles), manufacturing (CNC, CAD/CAM), services (financial, marketing, security, technical and management consultancy, trade promotion, tourism, leisure and sports… ). In final chapters, author explains how the central PSUs, state PSUs, big and small industries, MNCs, Academics and RnD labs, government and non-government organization can involve/help in achieving the vision.

This came to me as a surprise. In one of the chapters, author has mentioned that, When India achieved mile stones in aerospace and defense sector, western countries by publishing false statements tried to take away the credit from Indian scientists. This definitely shows that western countries want to control the world and does not want to let go off the power from their hands.

In some of the sectors, I think, we have surpassed the vision. This is mainly due to repaid change in technology which has resulted in solving problems with newer and easier approaches.

Advertisements
Posted in General Books | Leave a comment

All about Network File System (NFS)

As the name itself indicates it’s a file system on remote computer which can be accessed as a local filesystem on other computers in network.
Sharing file system in a network is a 3 step process
1. Start NFS service
To share/access files, NFS service should be running on the server which shares the file system. Download the script nfsServiceCheck, which check’s if NFS service is running and if it’s not running will start the service. This script caters to RHEL/SUSE/OEL and CentOS. For NFS service to be running properly, rpcbind service should be started first and then the NFS service, if it’s done in reverse order, file system cannot be exported. So make sure to start rpcbind service first and then the NFS service. Script attached in this post does take care of this while starting the NFS service. To use the script, create a shell script with the contents of file and execute the script (it does not accept any arguments) to start the rpcbind and NFS service. Script does not cater to stopping of service.

2. export the file system to other hosts in network
After the service is started, from the source server ( file system which needs to be accessed in other hosts ), filesystem should be exported.
If file system should continue to be exported even after system reboot, follow the below steps
#vi /etc/exports

Make the following entry in file
192.168.0.101(rw,sync,no_root_squash)
eg:
/nfsshare 192.168.0.101(rw,sync,no_root_squash)

Options:
ro: read only access to the shared files
rw: This option allows the client server to both read and write access within the shared directory.
sync: Sync confirms requests to the shared directory only once the changes have been committed.
no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
no_root_squash: This phrase allows root to connect to the designated directory.
* can be specified in place of IP address to share to all hosts in network.
Do refer to man page for all options detail

execute the below command, to export the file system which was entered in /etc/exports file above
#exportfs

If file system need to be exported only for short duration and need not continued to be exported after system reboot, follow below steps
execute the following command
#exportfs -o ro,all_squash *:
eg: exportfs -o ro,all_squash *:/opt/omni/

3. Mount the file system in other hosts
After the filesystem is exported from source server, file system needs to be mounted on client system where it needs to be accessed.
#showmount -e 192.168.0.100
This command will display all the NFS shares exported on host 192.168.0.100

If file system should continued to be mounted even after system reboot, follow below steps
# vi /etc/fstab
192.168.0.100:/nfsshare /mnt nfs defaults 0 0

execute the below command, to mount the file system for which a entry was made in /etc/fstab file above
#mount -a

If file system needs to be mounted only for short duration and need not be remounted after system reboot, execute following command in shell
#mount 192.168.0.100:/nfsshare /mnt/

Now filesystem 192.168.0.100:/nfsshare is accessible on 192.168.0.101:/nfs/nfsshare

Unmount the share from client hosts
If entry was made in /etc/fstab file, remove the entry from file and then execute the command
#mount -a
If entry was not made in /etc/fstab file and file system was mounted using the mount command from shell, use the below command for unmounting
#umount /mnt/nfsshare

For unexporting the share from source system
If entry was made in /etc/exports file, remove the entry and execute the command
#exportfs
If file system was exported from shell without making an entry in /etc/exports file, use the below command to unexport the file system
#exportfs -u *:

Posted in Unix and Unix Internals | Tagged , , , , , , | Leave a comment

Creating and linking static and shared libraries

In this post, i will explain how to create, link and access static and shared libraries.

Libraries can be created as
1. static library (.a)
2. shared library (.so)

Static library (*.a files) – these libraries are linked to application at compile time and become part of application itself. This increases the size of application.
Shared libraries (*.so files) – Most of us are aware of loading and unloading of dynamic libraries with dlopen(), but there is another method of linking the dynamic libraries. Shared libraries can be accessed in two ways.
a.Dynamically loaded/unloaded, using the dynamic linking loader system function
b.Dynamically linked at run time but statically aware. The libraries must be available during compile/link phase. The shared objects are not included into the executable component but are tied to the execution.

Example for creating static and shared library
———————————————-
//mean.c – file containing a method to calculate the mean
#include
double mean(double a, double b) {
return (a+b) / 2;
}

//mean.h header file
double mean(double, double);

Create object file from source file
#gcc -c mean.c -o mean.o

Create static library, libmean.a
#ar -cvq libmean.a mean.o
the library name must start with the three letters lib and have the suffix .a

Create shared library , libmean.so
#gcc -c -fPIC mean.c -o mean.o
#gcc -shared -Wl,-soname,libmean.so.1 -o libmean.so.1.0.1 mean.o
the library must start with the three letter lib

How to use the static and shared libraries in program
—————————————————–
//main.c where mean() defined in static/shared library is called
#include
#include “mean.h”

int main(int argc, char* argv[]) {

double v1, v2, m;
v1 = 5.2;
v2 = 7.9;

m = mean(v1, v2);

printf(“The mean of %3.2f and %3.2f is %3.2f\n”, v1, v2, m);

return 0;
}

Statically linked
—————–
#gcc -static main.c -L. -lmean -o statically_linked

Dynamically linked at run time but statically aware
—————————————————
#gcc main.c -o dynamically_linked -L. -lmean

Dynamically loaded/unloaded
—————————
In this method, compile the program with no reference to shared library. Shared library will be loaded/accessed/unloaded with the system calls dlopen(), dlsym() and dlclose(). Following is how this is done.

Following is the main.c file for dynamically loading and unloding shared libray
#include
#include “mean.h”

int main(int argc, char* argv[]) {

double *lib_handle;
double v1, v2, m;
v1 = 5.2;
v2 = 7.9;

lib_handle = dlopen(“/opt/lib/libmean.so”, RTLD_LAZY);
if (!lib_handle)
{
fprintf(stderr, “%s\n”, dlerror());
exit(1);
}

fn = dlsym(lib_handle, “mean”);
if ((error = dlerror()) != NULL)
{
fprintf(stderr, “%s\n”, error);
exit(1);
}

m = (*fn)(v1,v2);

printf(“The mean of %3.2f and %3.2f is %3.2f\n”, v1, v2, m);

return 0;
}
//compile the program
#gcc main.c -L. -o dynamically_linked

For more detailed information with example, refer to following link
http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
http://www.adp-gmbh.ch/cpp/gcc/create_lib.html

Posted in C Section | Leave a comment

About GPT/MBR disks and diskpart

One of the limitations of MBR partition is limitation of max disk size to 2TB. If disks of size greater than 2TB has to be used, it has to be converted to GPT disk rather than MBR. For more details on limitations on how does the partition look like, refer to below links

1. http://www.howtogeek.com/193669/whats-the-difference-between-gpt-and-mbr-when-partitioning-a-drive/
2. http://www.computerhope.com/jargon/g/gpt.htm
3. http://www.partition-tool.com/resource/GPT-disk-partition-manager/partition-gpt-disk.htm

Diskpart is a command line utility to manage disks, paritions and volumes. Diskpart command can also be used for convertion of disk to MBR or GPT. For all the options supported by diskpart command do refer to following links

1. http://www.computerhope.com/diskpart.htm
2. http://ss64.com/nt/diskpart.html
3. http://technet.microsoft.com/en-us/library/cc766465(v=ws.10).aspx
4. http://support.microsoft.com/kb/300415

Posted in General Tech Discussion | Tagged , , , , | Leave a comment

“What Got You Here Won’t Get You There” by Marshall Goldsmith, Mark Reiter.

The book is about, what and how to reach higher levels in corporate ladder from where you are now. Book explains about small consistent workplace habits which can make lot of difference which help in moving to next level.
I felt the content is similar to any of the other self improvement books. If other self improvement books are read, this may not a must read and can be given a miss.

I am not sure, if the workplace habits explained by author can be related to current corporate structure and how effective is it, as i think some of the habits will hinder timely execution of projects.

Posted in Personality Development Books | Leave a comment

Building static and shared log4cxx library on Windows and Linux

Recently we used log4cxx for logging in our product. It’s an open source framework and as usual not much documentation is available. We needed to build log4cxx in both windows and linux. First we built shared library on windows (dll) and as we started using the log4cxx we encountered issues which could not be solved. Then we decided to use static libray. Most of the issues were resolved by using static library.

Next we built log4cxx on Linux.

All this information is available at different locations. Here i am consolidating build process (static and dynamic) on both windows and linux

Building dynamic library in windows
—————————————————————–
Log4cxx Setup, Configuration and build on visual studio 2010

1. Download the latest log4cxx package from “http://logging.apache.org/log4cxx/download.html”
2. Download apr and apr-util ZIP packages from “http://apr.apache.org/download.cgi”
3. Extract log4cxx, apr und apr-util to the same directory
4. Rename apr_VERSION and apr-util_VERSION folder to apr and apr-util resulting in a directory with three folder: apache-log4cxx-0.10.0, apr
and apr-util
5. Change into the log4cxx directory and execute configure.bat
6. Change to apr-util/include directory and open apu.hw in a text editor of your choice
7. Find the entry #define APU_HAVE_APR_ICONV, set it to 0 and save the file
8. Open apr_ldap.hw from the same directory and find the entry #define APR_HAS_LDAP, set it to 0 and save the file, too.
9. Change to log4cxx/projects directory and open log4cxx.dsw with VS2010. Answer the converting prompts of VS2010 with yes/ok for each project
(apr, apr-util, log4cxx, xml)

Building log4cxx now will result in around 2000 errors.

Search (Ctrl+F) and find each entry of the “LOG4CXX_LIST_DEF” macro. Move these entries out of its related class and right before the same class. Sometimes it might be required to move a typedef too or add the class right before the macro.

Some examples:

// telnetadapter.h

typedef log4cxx::helpers::SocketPtr Connection;
LOG4CXX_LIST_DEF(ConnectionList, Connection);
class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton

// appender.h

class Appender;
LOG4CXX_PTR_DEF(Appender);
LOG4CXX_LIST_DEF(AppenderList, AppenderPtr);

class Layout;
typedef log4cxx::helpers::ObjectPtrT LayoutPtr;

class LOG4CXX_EXPORT Appender :
public virtual spi::OptionHandler
{

If the compiler complains about KeySet not being member of LoggingEvent, remove the scope (since we moved the type to outside the class in the previous step, these types no longer are inside the class)
Example:

// old
LoggingEvent::KeySet set;
// new
KeySet set;
If the compiler complains about insert_iterator not being in the namespace std, add #include to the include section of the source file.

Last but not least, right-click on log4cxx project and select Add References and select the other 3 projects as reference

TO COMPILE LOG4CXX AS A STATIC LIBRARY
—————————————————————————-
1) Open log4cxx project/solution
2) Go to log4cxx project, and open its properties dialog
3) Select Configuration Properties->General and set Configuration Type to Static Library (.lib)
4) Go to Configuration Properties->Preprocessor and add to Preprocessor Definitions the following (LOG4CXX_STATIC)
5) Go to Configuration Properties->Code Generation and set RunTime Library to Multi-threaded Debug (/MTd) or /MT
6) Also perform step#5 for apr, apr_util and xml projects
7) In log4cxx project (only for 64bit libray)
librarian->commandline-> add the option /MACHINE:X64
8) Build log4cxx
9) Result is a file named log4cxx.lib with about 37MB of space

HOW TO USE LIB4CXX AS A STATIC LIBRARY
—————————————————————————-
1) Use the same configuration /MTD or /MT for the project
2) add LOG4CXX_STATIC to Preprocessor Definitions
3) add the path of log4cxx.lib, apr-1.lib,aprutil-1.lib and xml.lib directory
4) Add all libs required namely (Linker->Input->Additional Dependencies)
WS2_32.Lib, MsWSock.Lib, AdvAPI32.Lib, odbc32.lib, log4cxx.lib apr-1.lib, apr_util-1.lib and xml.lib static libraries
5) Build your project

Building and static and dynamic log4cxx library on Linux
————————————————————————————————————–
TO COMPILE LOG4CXX
————————————
1) extract log4cxx, apr and apr-util
2) go to ../apr-util/xml/expat/
and execute
./configure CPPFLAGS=”-fPIC -Bstatic” –prefix=/staticlibs/ –with-pic –enable-static
make
make install

3) go to the apr home directory and execute the following
./configure CPPFLAGS=”-fPIC -Bstatic” –prefix=/staticlibs/ –with-pic –enable-static
make
make install

4) go to ../apr-util/
./configure CPPFLAGS=”-fPIC -Bstatic” –prefix=/staticlibs/ –with-apr=../apr
make
make install

5) modify some of the files
apache-log4cxx-0.10.0/src/main/cpp/inputstreamreader.cpp
apache-log4cxx-0.10.0/src/main/cpp/socketoutputstream.cpp

add directive “#include ”
and apache-log4cxx-0.10.0/src/examples/cpp/console.cpp
add directives

#include
#include

5) go to ../apache-log4cxx-0.10.0 folder
and execute
./configure CPPFLAGS=”-fPIC -Bstatic” –prefix=/staticlibs/ –with-pic –enable-static –with-apr=../apr –with-apr-util=../apr-util
make
make install

6) for compiling sample application with static library
use : g++ example.cpp -pthread -I/usr/local/include/ -L/staticlibs/ -llog4cxx -lapr-1 -laprutil-1 -lexpat
7) similarly shared library can be used for compiling example.cpp program
8) both log4cxx static and shared library will be placed under /staticlibs/ after build

References
——————–
http://stackoverflow.com/questions/8461123/building-log4cxx-in-vs-2010-c
http://mail-archives.apache.org/mod_mbox/logging-log4cxx-user/201002.mbox/%3C9cc05c621002180613l76d009f1v87ddeaaeffb50dd@mail.gmail.com%3E
http://letcoderock.blogspot.in/2012/08/build-log4cxx-on-windows.html
http://www.radmangames.com/programming/how-to-build-log4cxx-from-source

Posted in Open Source | Leave a comment

“What young India wants” by Chetan Bhagat

I was a bit skeptical before buying this book as Chetan Bhagat is a novel writer. Since author is a well know writer and i liked couple of movies based on his novel, went ahead and bought the book. This is the first book of Chetan Bhagat i have read :).

Many of us know the most common issues of India like corruption, our education system, political issues, corporate issues,terror attacks, corruption in cricket to mention a few. Book is all about this. Author has discussed about Anna Hazare movement which has finally led to down fall of congress government in Delhi. Book is just not only about the issues but has suggestions on how the issues could be resolved.

In my view, most of us know the issues discussed in the book. But the book is a documentation of all this at single place. Worth reading the book.

Posted in Personality Development Books | Leave a comment