Howto setup su root in ubuntu

By default, ubuntu distribution doesnt provide password for su/root user. Here is how to setup a password for su.

Run this on terminal. [ Ctlr + Alt + T ]

sudo passwd

Enter your password and it will ask for new password.
Enter it, and you are done.

More information : http://www.howtogeek.com/111479/htg-explains-whats-the-difference-between-sudo-su/

Threads Vs Process

From Robert Love on Quora
https://www.quora.com/What-is-the-difference-between-a-process-and-a-thread

Here is the analogy I use in Linux Kernel Development. Processes are the abstraction of running programs: A binary image, virtualized memory, various kernel resources, an associated security context, and so on. Threads are the unit of execution in a process: A virtualized processor, a stack, and program state. Put another way, processes are running binaries and threads are the smallest unit of execution schedulable by an operating system’s process scheduler.

A process contains one or more threads. In single-threaded processes, the process contains one thread. You can say the thread is the process—there is one thing going on. In multithreaded processes, the process contains more than one thread—there’s more than one thing going on.

The two main virtualized abstractions in modern operating systems are virtualized memory and a virtualized processor. Both afford the illusion to running processes that they alone consume the machine’s resources. Virtualized memory gives processes a unique view of memory that seamlessly maps back to physical RAM or on-disk storage (swap space). A virtualized processor lets processes act as if they alone run on the system, when in fact multiple processes are multitasking across (perhaps) multiple processors.

Virtualized memory is associated with the process and not the thread. Thus, threads share the same memory address space. Conversely, a virtualized processor is associated with each thread. Each thread is an independent schedulable entity.

What’s the point? We obviously need processes. But why introduce the separate concept of a thread and allow multithreaded processes? There are four primary benefits to multithreading:

Programming abstraction. Dividing up work and assigning each division to a unit of execution (a thread) is a natural approach to many problems. Programming patterns that utilize this approach include the reactor, thread-per-connection, and thread pool patterns. Some, however, view threads as an anti-pattern. The inimitable Alan Cox summed this up well with the quote, “threads are for people who can’t program state machines.”
Parallelism. In machines with multiple processors, threads provide an efficient way to achieve true parallelism. As each thread receives its own virtualized processor and is an independently-schedulable entity, multiple threads may run on multiple processors at the same time, improving a system’s throughput. To the extent that threads are used to achieve parallelism—that is, there are no more threads than processors—the “threads are for people who can’t program state machines” quote does not apply.
Blocking I/O. Without threads, blocking I/O halts the whole process. This can be detrimental to both throughput and latency. In a multithreaded process, individual threads may block, waiting on I/O, while other threads make forward progress. Asynchronous & non-blocking I/O are alternative solutions to threads for this issue.
Memory savings. Threads provide an efficient way to share memory yet utilize multiple units of execution. In this manner they are an alternative to multiple processes.

The cost of these benefits are increased complexity in the form of needing to manage concurrency through mechanisms such as mutexes and condition variables. Given the growing trend toward processors sporting multiple cores and systems sporting multiple processors, threading is only going to become a more important tool in system programming.

The Tata Fact’s – What they have given?

One of my friend have Written and shared this on Facebook.

At first I too thought, not to waste time reading this, But Its far more valuable than what I had thought.

I didnt knew most of these facts before 😦 Thought many of us would not have known these.

So, Im sharing this with you, as its written on the link below, with just few formatting for easy read.

Please, spend some time to read this.

Its Money or Knowledge or Love or what ever it is.
We are respected for what we give. Not for what we have.

Respect is earned! And such a respect will never fade away.

https://www.facebook.com/notes/arvind-devaraj/tata-factbook-for-facebook-generation/274731799207898

Thanks Arvind!

1) EXECUTIVE SUMMARY

These are the lesser known facts about Tata I came to know very recently . I wrote this note as I was pained to see some people linking all wealthy people with corruption. While facts about other great people are widely available on web, facts about Tata aren’t known much. Some information is present on books. Maybe Tatas deliberately haven’t focussed much on marketing their own goodness. Of late, there are ads like ‘Values stronger than steel’ from Tata. Compared to the magnum opus of their work, their publicity pales in comparison.

Even as a young kid, I have heard Tata’s name. “Tata Birla” is a term synonymous with rich. I knew about Tata as another business man who sought to become rich and succeeded. But there is much more….

2) PROFILES

(Jamshetji) J.N.Tata ( 1839 – 1904 )

Dorab Tata / Ratan Tata ( early 1900s )

JRD Tata ( 1930s till 1990s)

Ratan Tata ( 1990s – present )

3) LEGACY – SYNOPSIS

“Tatas represent the spirit of adventure,” – Mahatma Gandhi

J.N.Tata is the founder of the Tata empire . In the book ‘100 Great Modern Lives’ by John Canning only two Indians feature – Mohandas Karamchand Gandhi and Jamsetji Tata. The chapter on Jamsetji Tata concludes with the paragraph: ‘Probably no other family have ever contributed as much in the way of wise guidance, industrial development and advancing philanthropy to any country as the Tatas have to India, both before and since independence (1947).’

J.N.Tata’s sons Dorab and Ratan Tata would carry the legacy of J.N.Tata. Ratan Tata financially supported a then unknown lawyer in South Africa

protesting against British. The lawyer said during a meeting “We have got so much contributions from Tata and we have to work hard to justify that”.

That lawyer was Gandhiji. When Godrej asked for blessing from Gandhi to start a new product – Gandhi light heartedly replied – “If you are going to compete against my good brother Tata I wont be able to bless that”

After Dorab/Ratan , JRD Tata becomes chairman. JRD Tata was instrumental in giving wings to India by building Tata Airlines, which ultimately became Air India .Kalpana Chawla, the Indian-born astronaut cited JRD and his pioneering airmail flights as her inspiration for taking up aeronautics. In 1992, because of his selfless humanitarian endeavors, JRD Tata was awarded India’s highest civilian honor, the Bharat Ratna – rare for a businessman to get in the License Raj.

After JRD Tata, Ratan Tata becomes chairman in 1992.

4) HISTORY

COTTON MILLS

It was around 1870s. JN Tata purchases a small cotton mill. Over the next 20 years he made it successful one. He was a running a successful business in India. The most significant thing is the way he treated his employees – sick leaves / hospital facilities / school for children / Provident Fund / Life Insurance/ Room conditioners to prevent dust. All these seems trivial in today’s world. But in the industrial age, even workers in England worked in very inhuman conditions and facilities like insurance were unheard of. ( the condition of workers in that era is captured well in many of Charles Dicken’s novels ).

It was 1890 – JN Tata was fifty years of age and a reputed businessman employing thousands of people . The story till now alone would suffice to have his mark in India’s history. But still more to come…

Tata was on a sea voyage where he me Swami Vivekananda. Swami tells him that the future of India is in young people – especially young people working in science and research have to ability to rewrite the history of nation. The term ‘Science’ for many businessmen may not mean much… but Tata was not a mere businessman. This meeting with Swami Vivekanand would turn important and establish basis for scientific research in India.

5) TAJ HOTEL

when British ruled us, Indians were not allowed to enter star hotels. Tata was determined to build a fine hotel where Indians wouldnot be treated as an outcaste and thus Taj Hotel was born

6) TATA STEEL

“The nation that has the steel has the gold” – these were the last words in a talk attended by Tata in England given by an eminent scholar. These words were ringing in Tata’s mind for next decade of his life. JN Tata would lay the foundation of steel empire. He died in 1904, but his dream would be carried forward by his sons Dorab and Ratan. He had left detailed instructions about the steel plant. “We are not just building factories…we are building cities around a factory….we are enriching lives…in the factory complex – make sure you allocate space for schools / day care centres / hosptials / places of worship – temples, mosques, churches ”

The British were skeptical of Tata’s ability to produce steel. “The Indians are making steel? The Indians can’t run a shop properly” The Governor said “Why I offer to eat every pound of steel Tatas produce” Later the Tata steel plant began to produce successfully . Dorab Tata said if the Governor had kept his words , he would have a slight indigestion. The British would later order steel from Tata during the World war as Tata steel was more robust in making bullet proof shields in vehicles. That time the steel was produced in a small village in Bihar called Sakshi. Later the city would be renamed in honor of Jamshedji Tata as Jamshedpur

At Tata Steel, not only steel but also men were forged in Jamshedpur. That’s why it’s a place where India is still shining, it’s a place where the nation of India was transformed and it’s a place that was selected as a UN Global Compact City because of the quality of life, conditions of sanitation,roads and welfare that were offered by Tata Steel

7) INDIAN INSTITUTE OF SCIENCE

Swami Vivekananda’s meeting was still on the mind of Tata. Tata wanted to establish an institute of higher learning focussed on research. Unlike setting up hotels or industry, he needed Governments permission for setting up educational institute. The man in power and who had to give permission was Lord Curzon ( the man who partitioned Bengal ) . When he told Curzon of his plan , Curzon replied- You mean the Indian students have the ability to undertake scientific research – Where will you find teachers for such advanced courses and where will you find students who can grasp such concepts…And what will students do with such advanced degrees if they are anyway going to work as a clerk after completion . In short “Surely, You are joking Mr.Tata”. After the meeting with Curzon, every one in Tata’s team was heart broken. They were cursing Curzon .. Tata replied to them “Lets wait for Curzon’s mind to change – there must be some good in him somewhere”

The permission to setup the institute came years after JN Tatas death. JN Tata had instructed his sons to carry on the struggle of establishing the institute after his death.. A newspaper in US wrote “The amount millions is more than enough to establish an university in US and in a country like India it is a great amount”.

J.N.Tata gave one third of his wealth to establish IISc. He had 2 sons Dorab and Ratan, so many consider that he considered IISc to be his another child. Originally the institute was to be setup in Bombay. The nobel prize winning scientist Ramsey was asked to tour India to find the best place conducive to research. He suggested Bangalore, but Tata favored Bombay. Finally, the Maharaja of Mysore offered vast amount of lands and persuaded Tata to setup the institute at Bangalore.

8) AVIATION

JRD Tata was the first Indian to have flying license.His license reads #1. His interest in aviation caused him to start Air India and Indian Airlines. The Maharaja symbol of these airlines was his conception. Air India was providing the finest service in aviation at moderate rates until its take over by Government.

9) SCHOLARSHIPS

Tatas provide scholarship for people who have potential , but economic condition prevent them continuing their studies. One such candidate applied to Tata for scholarship. Though his love was political science, he chose to enroll in English literatue due to financial constraints . After analyzing the applicant, the Tatas persuaded him to study political science offering to pay the entire tuition fees and provide stipend for expenses also. This incident was later narrated by K.R.Narayanan who became President of India. If not for the scholarship, K.R.Narayanan might have become professor in English literature.

Every year thousands of people apply for Tata scholarship, even among wealthy people. There is a pride in being a Tata Scholar. There are people like Raja Ramanna ( space scientists) and many more who benefited from it.

In 1912, the London School of Economics established the Ratan Tata Department. The following year it advertised for a position of a lecturer in that department for which two people applied. One was a young man called Clement Atlee, who after careful consideration was selected for this position. About 32-years later Atlee became the Prime Minister of Britain. Interesting enough that it was under his government that India was granted independence in 1947.

10) INSTITUTES

Tata Memorial hospital – Focuses on Cancer research . Tatas lost few of their family members to cancer and they are supporting research

TIFR ( Tata institute of fundamental research ) – from wikipedia

“In 1944, Dr. Homi J. Bhabha, known for his role in the development of the Indian atomic energy program, wrote to Sir Dorabji Tata Trust requesting financial assistance to set up a scientific research institute.[2] With support from J. R. D. Tata, then chairman of the Tata Group, TIFR was founded on 1 June 1945, and Homi Bhabha was appointed its first director”

NCPA- National center for performing arts

TISS – Tata institute of social sciences

11) CSR (Corporate Social Responsibility)

from wikipedia

“In general, about 66% of the profits of Tata Group go to charity and executives made it clear that they have no intention of leaving control to Wall Street.[21] The charitable trusts of Tata Group fund a variety of projects, for example the Tata Swach and the TCS project. They founded and still support such cherished institutions as the Indian Institute of Science, Tata Institute of Fundamental Research, the National Centre for the Performing Arts and the Tata Memorial Hospital. Each Tata Group company channels more than 4 percent of its operating income to the trusts and every generation of Tata family members has left a larger portion of its profit to them. This makes the Tata family evidently less wealthy as individuals than other Indian family-owned companies.[19]”

12) FRIENDS

Sudha was studying in IISc and it was placement season. There was a notice ‘Tata group is hiring’. Unfortunately there was a P.S stating “Only male candidates can apply’ . Sudha was very angry on seeing this – what qualification preclude me from applying to this job. She wrote an angry letter to JRD Tata venting out her anger – though she never expected any reply. The next day, she was called to meet JRD Tata and he explained that the job required physical endurance and thats why women were dissuaded from that job. However Tata offered Sudha that position

Later Sudha would leave Tata group to start Infosys with her husband Narayana Murthy. she said to Tata “Let me try how things work out in Infosys”, Tata replied “There is no try…I know you and Murthy very well, you will definitely succeed ”

13) GROUPS

TCS with 200,000 employees is one of largest private sector employers. TRDDC was the research wing of TCS. One of its products ‘Tata swach’ aim to provide low cost water purifier. They diversified into many more areas

and have become brands in their own right like Voltas, Tanishq , Titan, Star bazaar, Tetley. Lakme was established when Nehru banned import of cosmetics and suggested to Tata that we need Indian products.

13) WALL

“Acquried Jaguar LandRover” – million likes

“Acquired Corus ” – million likes

The acquired companies are great European companies. Only few decades back, getting employed in an European company was a dream come true . Owning an European company was far from our dreams.

14) POKES

Air India and Indian Airlines were taken over by the Government when they nationalized Airlines. JRD Tata was stripped of his chairman position and this was not even informed to him. Only the succeeding chairman called him on phone and informed that he is taking over. Many other constraints during the license raj as the general philosophy of the govt was that businessmen are evil people.

15) NETWORK

The Tatas are of Parsi origin – descend from a group of Zoroastrians of Iran who immigrated to India during an invasion in 10th century. The then Gujarat king offered home for them. The Parsis would become prominent – Pherozeshah Mehta, Dadabhai Naoroji, Bhikaiji Cama, Homi Bhaba, Homi Sethna, Godrej, Wadia, Shapoorji Pallonji, Zubin Metha, Field Marshal Manekshaw. Thanks to that King for allowing the Parsis. The parsi belief is ‘HUMATA HUKTA HAVARASHTA’- meaning good thoughts, words, deeds. Think about it – they are technically foreigners. And they have done greater good than many politicans with ancestral origins in India.

15) REFERENCES

R.M.Lala’s books on Tata especially “For the love of India”. Rare old books in IISc Library . Not much is available on net. (once was excited to find a promising youtube video – later it was on Tata Young singing Dhoom Dhoom….)

Before coming to IISc , I knew Tata only as a businessman. In IISc, the name of Tata was omnipresent – Tata Auditorium, Tata Library. Tata is the chairman of the IISc trustees. IISc itself is known only as Tata institute in bangalore. I first thought why should a government institute like IISc have to associate so much with Tata, I also thought such associations might affect the autonomy of the institute. Later I realized the very existence of the institute owes to legacy of Tata.

And I have already searched for this book, [http://www.goodreads.com/book/show/2435387.100_Great_Modern_Lives]
but unluckily, i could get this. If anyone have it or any pointers, please let me know.

Link to same text as a PDF. Not much attractively formatted. But its easy to read and share.Tata

bc, Shell or cli Calculator

You can do calculations on your CLI/Shell/Terminal itself.
There is a utility called bc.

From man page,:

NAME bc – An arbitrary precision calculator language

SYNTAX bc [ -hlwsqv ] [long-options] [ file … ]

DESCRIPTION bc is a language that supports arbitrary precision numbers with interactive execution of statements. There are some similarities in the syntax to the C programming language. A standard math library is available by command line option. If requested, the math library is defined before processing any files. bc starts by processing code from all the files listed on the command line in the order listed. After all files have been processed, bc reads from the standard input. All code is executed as it is read. (If a file contains a command to halt the processor, bc will never read from the standard input.) This version of bc contains several extensions beyond traditional bc implementations and the POSIX draft standard. Command lineoptions can cause these extensions to print a warning or to be rejected. This document describes the language accepted by this processor. Extensions will be identified as such.

Some simple example :

# 10+20
echo “10+20” | bc

# Convert decimal number 10 to hexadecimal number
echo “obase=16; 10” | bc

# Convert Hexadecimal number 10 to decimal number
echo “ibase=16; 10” | bc

# Convert Binary number 10 to decimal number
echo “ibase=2; 10” | bc

# Convert Decimal number 10 to Binary number
echo “obase=2; 10” | bc

You can also use printf, ofcourse, yes its like C.. 😛 as below

printf ‘%x’ 16

Optical Character Recognition in Ubuntu

Today, I was trying to capture some logs from QEMU. But unfortunately, i couldnt start logging qemu easily.
So Thought to capture the image and take up OCR to get text. Ubuntu has gocr, which i could use.

Installing gocr:

sudo apt-get install gocr

Using GOCR :

gocr -h for list of usage

Simply to extract text from a screenshot, i followed this.

raj@14:19:31:$ gocr -i ~/Pictures/Screenshot\ from\ 2012-11-25\ 14\:18\:40.png -o out.txt

Output is pretty acceptable, even though its not accurate.

Leaf and Non-Leaf procedure in MIPS

A leaf procedure is a procedure/function, which doesnt call any other procedure.

Example :

int leaf_procedure()
{
  int return_value;

  ...
  ...
return return_value;
}

A non-leaf procedure is a procedure/function, which call’s some other procedure within them.

Example :

int non_leaf_procedure()
{
  int return_value;

  ...
  leaf_procedure()
  ...
return return_value;
}

Simply, we can tell all recursive functions are non-leaf procedures. And we need atleast one leaf procedure to any program to exit, atleast in a normal way. 😉

Simple Hello world c programm and Makefile to start with Shared library in linux

Goal : To create a Make file to generate an executable using makefile in Ubuntu.
Requirements : Ubuntu, Knowledge of c programming.

First we will create a simple hello world c program.

Creating the source code for Hello World Program:

Contents of main.c

    #include
    int main()
    {
        printf("Hello world!");
    }

Compiling the source file using gcc

gcc main.c

This will generate a executable file as a.out.

1.b Generating a executable file with a given name

gcc main.c -o hello

1.c Modularising the print function

Modularising is good as they can be reused, archived as library, and for many more reasons

#include
void print_hello();

void print_hello()
{
printf("Hello world!");
}
int main()
{
print_hello();
}

1.d Creating seperate files for modules:
Its good to have releatives modules in a sepearate files

Content of main.c

int main()
{
print_hello();
}

Content of hello_func.c

#include
void print_hello()
{
printf("Hello world!");
}

Compiling the files

gcc hello_func.c main.c -o hello.out

1.d Creating header files

Every c file will have some header files included.

Content of main.c

#include "hello.h"
int main()
{
print_hello();
}

Content of hello_func.c

#include "hello.h"
void print_hello()
{
printf("Hello world!");
}

Content of hello.h

#include
void print_hello(void);

1.e Organizing the files

Its good to put up files in a organized manner.
So we put our modules, main and header files into source, test and include dirctory respectively as bellow.
And build directory to do the building.
.
├── build
├── include
│ └── hello.h
├── src
│ └── hello_func.c
└── test
└── hello.c

Compiling

cd build
gcc -I ../include/ ../src/hello_func.c ../test/hello.c -o hello.out

This will generate a hello.out in build directory

Now, we have very few files and its easy to manually use gcc to compile the code. But when the code grows,
Its difficult to handle build manually. So, now, we can create a makefile to build the code

2 Creating Makefile

we will put the same command used to build previously, but with little modifications.
I will say little enhancements, like bellow

Contents of Makefile

hello : ../include/hello.h ../src/hello_func.c ../test/hello.c
gcc -I ../include/ ../src/hello_func.c ../test/hello.c -o hello.out

hello : This is the Rule name
What ever following after the ‘:’ are the dependencies to be checked for.
Means, presence of these files will be checked before running the rule

Next line, starts with TAB. This defines actually what has to be run

Now, we can build the code using makefile by running the command ‘make’

3 Enhancing the Makefile

Now, we can take our makefile to the next step. Enhancements.
Still our code is very simple. We just have evry few files, so we can write the names manually.
What if the number of files is getting increased? We should make the Makefile easy to manage.

Contents of Makefile

PROJECT_NAME = hello
COMPILER = gcc

INCLUDE_DIR = ../include
TEST_DIR = ../test
SRC_DIR = ../src
EXECUTABLE_NAME = hello.out

SRC_FILES = ${SRC_DIR}/hello_func.c
TEST_FILES = ${TEST_DIR}/hello.c
INCLUDE_FILES = ${INCLUDE_DIR}/hello.h

${EXECUTABLE_NAME} : ${INCLUDE_FILES} ${SRC_FILES} ${TEST_FILES}
${COMPILER} -I ${INCLUDE_DIR} ${SRC_FILES} ${TEST_FILES} -o ${EXECUTABLE_NAME}

We are aliasing the names in more readable forms by assigning it to some variables or defines.

Now we can build using make command