Saturday, September 18, 2010

What is the difference between a thread and a process?

What is the difference between physical memory addresses and virtual memory addresses? What is a page table / page table entry?

What is the difference between kernel mode and user mode? What is a system call?

What is a spinlock? Why would you use one? When and when not?

What is a context switch? What happens when a thread is "blocked"?

What does the scheduler do?

What happens (to the state of a running thread) when an interrupt occurs?

What sorts of things must an interrupt handler do?

Why you want to write a device driver?

How will you register it?

How will you keep track of its usage?

Under what license will you write your driver?

How will you allocate memory in your driver?

Why not vmalloc?

What if you got to know that your memory is leaking?

What is IRQ? how will you register your IRQ no? Are you sure you will get the IRQ no you have requested? What if you don't get?

Where will you place filesystem? above device driver or below it?

Thursday, September 9, 2010

Setting up Version Control systems in Linux

Version Control System fits the definition of a friend in the common adage "A friend in need is a friend indeed " , for a software coder , who writes millions of lines of code over his lifetime , most of the times updating / improving his code .

An orderly life certainly warrants the need of keep a check of all the "Kodak Moments of life" , when a certain combination of the code worked brilliantly , bringing a smile on the developers face.

Over the course of time , the code is updated for getting a bigger smile .. but yeah sometimes one is not able to remember or browse through the whole source code to find out as to where the error has crept in from . And any frantic search of the Kodak Moment in the memory just does not seem to work out .

This is where the CVS comes to the rescue , as it acts as the database , which has stored the snapshots of the code , perhaps with a comment about those glorious days of the working code .

Just download the base-lined version and voila , it works . Now its just needed to compare what the updated code has more in it , that caused the error.

Subversion is an alternative to CVS that is growing in popularity.

apt-get install subversion subversion-tools

Creating a Repository :

Create a directory by the name repo/ under your home folder say /home/rajesh/

This is the place where we would be placing the repositories of all the projects that I am working on . This is different from my workspace directory.

timesheetapp is the application that I am working on and I want to keep a repository of that .

svnadmin create ~/repo/timesheetapp

The contents of the folder would look like this :
rajesh@rajesh-desktop:~$ ls -lrt /home/rajesh/repo/timesheetapp/
total 24
-rw-r--r-- 1 rajesh rajesh 229 2010-09-09 12:29 README.txt
drwxr-xr-x 2 rajesh rajesh 4096 2010-09-09 12:29 locks
drwxr-xr-x 2 rajesh rajesh 4096 2010-09-09 12:29 hooks
drwxr-xr-x 2 rajesh rajesh 4096 2010-09-09 12:29 conf
drwxr-sr-x 6 rajesh rajesh 4096 2010-09-09 12:29 db
-r--r--r-- 1 rajesh rajesh 2 2010-09-09 12:29 format

For optimum use of the subversion its advisable to use create a directory structure
mkdir timesheetapp
mkdir timesheetapp/trunk
mkdir timesheetapp/branches
mkdir timesheetapp/tags
svn import . file:///home/rajesh/repo/timesheetapp --message 'Creating repository for timeSheetApp

Steps for Creating a debian package installer for an application in Linux

Debian Package

Debian packages are standard Unix archives that include two gzipped, bzipped or lzmaed tar archives: one that holds the control information and another that contains the data.

The canonical program for handling these packages is dpkg, most commonly via apt/aptitude. [apt/aptitude are programs for application installers that come by default with Ubuntu]

A deb file contains two main files :

  • control.tar.gz
  • data.tar.gz
Certain things to be kept in mind for Linux

1) All executable binaries in Linux are usually to be installed under /usr/bin/ ; /usr/sbin/ ; /bin/

Why ? Coz these directories are added to the global PATH variable and all files are accessible from any folder.
To try this out : Open a terminal , type echo $PATH
You will see a number of directories , these are all having binaries / executables which can be accessed from any location . E.g the command 'cat' or 'ls' are all built-in executables that are present under /bin/ which is available in the PATH variable.

/home/rajesh/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

2) To find out the dependent shared libraries for an executable , try the ldd command

Why ? Coz this would give the libraries required by this executable , and can thus be listed in the control file of the .deb
Now we can see a step by step approach to creating a debian package with an example :

control file : This is the main “brain” of a debian file: it contains all of the informations reguarding this package, without this file the entire creation of a deb package has no meaning at all. A control file looks like this
__________________________________________________________________________________________________________
Package: ModBusTCPSim
Version: 1.01
Architecture: i386
Maintainer:
Installed-Size:
Depends:
Section: apps
Priority: optional
Description: ModBus TCP/IP Slave Simulator

ModBus TCP / IP Slave Simulator is a GUI implementation of the Slave Code of Modbus , built on the Sunlux Slave Stack Library.
This finds use as an slave simulator running on Linux / Ubuntu .
Original-Maintainer: Rajesh CB cb.rajesh.in@gmail.com>
________________________________________________________________________________________________________
  • Package: you have to put here the name of the package, never use spaces, never use a version number. It is case sensitive, be warned!
  • Version: of course, the version number / code. It can also be, for example, opengeu-3.0.2 or any other weird code, as long as the last part is a number. Always remember that chaning the version to a higher number triggers the system to consider that new file as an update of course!
  • Priority: optional, high, low, only system or security updated should have something like high in the priority.
  • Architecture: i386, amd64, all, you should specify here what platform this package is compiled for. If it is only an artowork or a metapackage, you can put all in the Architecture field.
  • Depends: a list of all the packages this package depends on. A metapackage, for example, can include almost nothing but depend on a lot of other packages so that installing this metapackage automatically installs a lot of other packages! That’s what happens with opengeu-desktop for example!
  • Conflicts: if you know that your package can’t work if another package is installed, well, you should then list that package here.
  • Description: put only a very short description in the first line, then enter a longer description on the second line, like it is shown in the example above.
Data
Every file that has to be installed into the system goes into the debian folder. Let’s say that this is like the heart of our deb package. Consider this folder as the “/” mount point of your system, the main system folder or whatever you call it. Basically, you have to recreate into the debian folder the structure of the folders and files you wish to be installed into the system. So, let’s say that our package has to install the ModBusTCPSim into the /usr/bin/ModBusTCPSim

then, you’ll have to create or edit the files and folders status to look like this:

Rajesh/debian/usr/bin/ModBusTCPSim

The final debian package creation :

Thus the final directory structure would look like this :

Rajesh/
`-- debian
`-- DEBIAN
|-- control
`-- usr
`-- bin
`-- ModBusTCPSim

Now cd to the folder Rajesh/ through a terminal and execute the command dpkg-deb –build debian
and you will have the debian.deb package created under the folder Rajesh/

We can rename or move the folder to a better name by :


mv debian.deb ModBusTCPSim.deb

'mv' - move command in Linux


Now through the GUI double click on
ModBusTCPSim.deb and the package gets installed.

Grey areas :

1) control can either be a file or a
control.tar.gz zipped archive of some more packages fro data integrity check.
2) This is a very basic set of files required to make a debian package , and does not contain all checks for data corruption et all , good debian packages contain manuals for the application too.