Monday, March 21, 2011

Android - Skeleton



Some parts of Android is familiar to all of us, such as the Linux Kernel, OpenGL, and the SQL database. Others may be completely foreign, such as Android’s idea of the application life cycle.



Starting at the bottom is the Linux Kernel. Android uses Linux for its device drivers, memory management, process management, and networking. However you will never be programming to this layer directly.

The next level up contains the Android native libraries. They are all written in C/C++ internally, but you’ll be calling them through Java interfaces. In this layer you can find the Surface Manager (for compositing windows), 2D and 3D graphics, Media codecs (MPEG-4, H.264, MP3, etc.), the SQL database (SQLite), and a native web browser engine (WebKit).

Next is the Android runtime, including the Dalvik Virtual Machine. Dalvik runs dex files, which are converted at compile time from standard class and jar files. Dex files are more compact and efficient than class files, an important consideration for the limited memory and battery powered devices that Android targets.

The core Java libraries are also part of the Android runtime. They are written in Java, as is everything above this layer. Here, Android provides a substantial subset of the Java 5 Standard Edition packages, including Collections, I/O, and so forth.

The next level up is the Application Framework layer. Parts of this toolkit are provided by Google, and parts are extensions or services that you write. The most important component of the framework is the Activity Manager, which manages the life cycle of applications and a common “back-stack” for user navigation.

Finally, the top layer is the Applications layer. Most of your code will live here, along side built-in applications such as the Phone and Web Browser.

One of the unique and powerful qualities of Android is that all applications have a level playing field. What I mean is that the applications Google writes have to go through the same public API that you use. You can even tell Android to make your application replace the standard applications if you like.

Libraries

Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below:

  • System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices
  • Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
  • Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications
  • LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view
  • SGL - the underlying 2D graphics engine
  • 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer
  • FreeType - bitmap and vector font rendering
  • SQLite - a powerful and lightweight relational database engine available to all applications





Saturday, September 4, 2010

What is Cloud Computing?

Cloud computing is Internet-based computing, whereby shared resources, software, and information are provided to computers and other devices on demand, like the electricity grid.





Thursday, August 26, 2010

Make and receive calls in Gmail


Google Voice lets you manage all your phone communications and seamlessly make and receive calls on any of your existing phones. But what if you don’t have your phone with you? Or what if you’re in a place with poor cell phone reception, or you’re traveling internationally and don’t want to incur expensive roaming charges? Wouldn’t it be great if you could use your computer to make or receive calls? Starting today you can use Gmail to receive or place Google Voice calls. To get started, check the box next to Google Chat in your list of forwarding phones and the next time someone calls your Google Voice number, Gmail will notify you of an incoming call. You can take the call or even listen in as the caller leaves a message, in a single step right from your computer.


Thursday, January 28, 2010

iPad

Apple iPad

The iPad is a tablet computer developed by Apple Inc. It features multi-touch interaction with print, video, photo, and audio multimedia, internet browsing, and runs most iPhone OS apps. The device has an LED-backlit 9.7-inch (25 cm) color LCD display and uses a virtual keyboard for text input. Prices for models in the United States range from $499 to $829 depending on the amount of storage and inclusion of 3G access.




Hardware specifications of Apple iPad

Model Early 2010
Announce date January 27, 2010
Color display 9.7 inches (25 cm) LED backlit in-plane switching LCD, made by Innolux, a subsidiary of Foxconn[2][15][16]
Processor 1 GHz Apple A4 system-on-a-chip[2][3]
Graphics 1024×768 pixel (XGA resolution), 20cm × 15cm, 132ppi
Storage 16, 32 or 64 GB flash memory
Wireless Integrated 802.11a/b/g/n and Bluetooth 2.1 + EDR
3G Internet 7.2 Mbps HSDPA
Operating system iPhone OS
Battery Built-in lithium-polymer 25 W·h (10 h usage, 1 month standby)
Weight 1.5 pounds (680 g), 1.6 pounds (730 g) (3G Model)
Dimensions 9.56 inches (24.3 cm) x 7.47 inches (19.0 cm) x 0.5 inches (1.3 cm)

Friday, January 8, 2010

Google Nexus One

Google Maps Navigation is an internet-connected GPS navigation system with voice guidance. It is part of Google Maps for mobile and is available for phones with Android 1.6 and higher.

Google Maps Navigation uses your phone's internet connection to give you the latest maps and business data. But that's not all that's different about Google's approach to GPS navigation. Watch the below video to learn more.




Nexus One

The Nexus One is a smartphone from Google that uses the Android open source mobile operating system. The device is manufactured by Taiwan's HTC Corporation, and became available on January 5, 2010. Features of the phone include the ability to transcribe voice to text, noise canceling dual microphones, and voice directions while driving.



Software : Android (operating system)

The Nexus One runs the Google Android 2.1 operating system, codenamed 'Eclair'. The 2.1 firmware version of the Android operating system adds a few aesthetic changes such as "Live Wallpapers" which are animated in the background and react to different user inputs. Android-based phones have access to more than 18,000 applications. It also replaces the "Application Drawer" with a single button which can be pressed to access the list of applications installed on the phone. This thumbnail list can be scrolled up and down and as it's scrolled, the applications roll up into a 3D cube instead of disappearing from the screen. Once the bottom of the application thumbnail list is hit, the screen bounces off similar to the iPhone functionality.




Android (operating system)


Android is a mobile operating system running on the Linux kernel. It was initially developed by Android Inc., a firm later purchased by Google, and lately by the Open Handset Alliance. It allows developers to write managed code in the Java language, controlling the device via Google-developed Java libraries.

Software development kit

The Android SDK includes a comprehensive set of development tools. These include a debugger, libraries, a handset emulator (based on QEMU), documentation, sample code, and tutorials. Currently supported development platforms include x86-architecture computers running Linux (any modern desktop Linux distribution), Mac OS X 10.4.8 or later, Windows XP or Vista. Requirements also include Java Development Kit, Apache Ant, and Python 2.2 or later. The officially supported integrated development environment (IDE) is Eclipse (3.2 or later) using the Android Development Tools (ADT) Plugin, though developers may use any text editor to edit Java and XML files then use command line tools to create, build and debug Android applications as well as control attached Android devices (e.g., triggering a reboot, installing software package(s) remotely).

Android Applications are packaged in .apk format and stored under /data/app folder on the Android OS. The user can run the command adb root to access this folder as only the root has permissions to access this folder.


Saturday, October 10, 2009

Google Wave

Google wants to create a wave, yet again. With Google Wave, a new tool that allows users to email, chat, play games, hold video conferences, edit documents, add images and conduct search, all in a single window.



Google Wave is a real-time multifaceted communication and collaboration platform.

It unifies different web technologies such as email, instant messaging, wiki, online documents and social networking.




Google Wave works on the idea of providing a real-time communication and collaboration by integrating established and emerging web technolgies.

Colayer, a Swiss-Indian software company, already provides a platform for companies to communicate, collaborate and co-create by building interactive social Web 2.0 environment

Microsoft, which is trying hard to catch up with Google on the internet, and Yahoo are widely expected to come up with Wave-like offerings. Buying out Colayer may be an option all three might be looking at.


What is a wave?

A wave is equal parts conversation and document. People can communicate and work together with richly formatted text, photos, videos, maps, and more.

A wave is shared. Any participant can reply anywhere in the message, edit the content and add participants at any point in the process. Then playback lets anyone rewind the wave to see who said what and when.

A wave is live. With live transmission as you type, participants on a wave can have faster conversations, see edits and interact with extensions in real-time.

Wave terminologies

Wave: A container for enhanced set of threaded conversations that is viewable as a document. It modifies real time and stores historical information.

Wavelet: A threaded conversation spawned within a wave. All participants on a wavelet have read/write access to content within the wavelet.

Blip: A single message that appears in a wavelet.

Participants: Each wave has a set of one or more participants who engage and interact in a wave. Participants are added to a wave by existing participants.

Saturday, January 31, 2009

Embedded Software Development Environments




Embedded Software Development Environments

* Operating systems used in embedded systems
* Programming languages used in embedded software development
* Development tools for writing embedded software
* Tools for device driver development

Operating Systems

Without its software, a computer is basically a useless lump of metal.
- “Operating Systems: Design and Implementation”

The embedded system has to interact with hardware to achieve the desired functionality. This interaction consists of efficiently managing the input/output operation, the memory, the various tasks to be carried out, the resource allocation of specified tasks, etc. Generally, all of these functions are achieved through an operating system.



Architecture of a typical Operating system kernel

Kernel architecture

In computing, the kernel is the central component of most computer operating systems. Its responsibilities include managing the system's resources (the communication between hardware and software components). As a basic component of an operating system, a kernel provides the lowest-level abstraction layer for the resources (especially memory, processors and I/O devices) that application software must control to perform its function. It typically makes these facilities available to application processes through inter-process communication mechanisms and system calls. The following architecture is applicable to both desktops and embedded systems.



The kernel's primary purpose is to manage the computer's resources and allow other programs to run and use these resources. Typically, the resources consist of:

* The Central Processing Unit (CPU, the processor)
* The computer's memory
* Any Input/Output (I/O) devices present in the computer, such as keyboard, mouse, disk drives, printers, displays, etc.

Kernels also usually provide methods for synchronization and communication between processes (called inter-process communication or IPC).


What is a Kernel?

The kernel is the central part of an operating system, that directly controls the computer hardware. Usually, the kernel is the first of the user-installed software on a computer, booting directly after the BIOS. Operating system kernels are specific to the hardware on which they are running, thus most operating systems are distributed with different kernel options that are configured when the system is installed. Changing major hardware components such as the motherboard, processor, or memory, often requires a kernel update. Additionally, often new kernels are offered that improve system security or performance. The two major types of kernels competing in today's computer markets are the Windows kernel and the unix-like kernels.

The Windows kernel is available only with the Microsoft Windows series of operating systems. It is proprietary software, developed and distributed by Microsoft Corporation. Introduced in Windows/386, it's many incarnations have since gone by several different names, and some had no names at all. The latest version of the Windows kernel was introduced in Windows NT, and has had many of it's functions removed and placed in user-mode software for Windows Vista. This leads to increased system stability and security. In Vista, application-level software exploits have much less access to the core functions of the operating system, and application crashes will not bring down the OS.



Unix-like kernels are a family of operating system kernels that are based upon, or operate similar to, the original Bell Labs UNIX operating system. Common examples of unix-like kernels are the Linux kernel, BSD, Mac OS, and Solaris. While many of these kernels were developed with original Bell Labs code as part of the software, not all of them have direct lineage to Bell. Linux, for instance, was developed as a free alternative to Minix, itself an independently developed variation of UNIX. Although originally running an original kernel design, Mac OS was outfitted with a unix-like kernel in 1988 with the introduction of A/UX. All subsequent Apple operating systems have unix-like kernels, including the current Mac OS-X's BSD-derived kernel.

Saturday, November 22, 2008

Embedded Systems


What is an Embedded System?

A specialized computer system that is part of a larger system or machine. Typically, an embedded system is housed on a single microprocessor board with the programs stored in ROM. Virtually all appliances that have a digital interface -- watches, microwaves, VCRs, cars -- utilize embedded systems. Some embedded systems include an operating system, but many are so specialized that the entire logic can be implemented as a single program.


OR

An embedded system is some combination of computer hardware and software, either fixed in capability or programmable, that is specifically designed for a particular kind of application device. Industrial machines, automobiles, medical equipment, cameras, household appliances, airplanes, vending machines, and toys (as well as the more obvious cellular phone and PDA) are among the myriad possible hosts of an embedded system. Embedded systems that are programmable are provided with a programming interface, and embedded systems programming is a specialized occupation. Certain operating systems or language platforms are tailored for the embedded market, such as EmbeddedJava and Windows XP Embedded. However, some low-end consumer products use very inexpensive microprocessors and limited storage, with the application and operating system both part of a single program. The program is written permanently into the system's memory in this case, rather than being loaded into RAM (random access memory) like programs on a personal computer.







Examples of embedded systems

PC Engines' ALIX.1C Mini-ITX embedded board with AMD Geode LX 800 together with Compact Flash, miniPCI and PCI slots, 44-pin IDE interface and 256MB RAM
An embedded RouterBoard 112 with U.FL-RSMA pigtail and R52 miniPCI Wi-Fi card widely used by wireless Internet service providers (WISPs) in the Czech Republic.

Embedded systems span all aspects of modern life and there are many examples of their use.

Telecommunications systems employ numerous embedded systems from telephone switches for the network to mobile phones at the end-user. Computer networking uses dedicated routers and network bridges to route data.

Consumer electronics include personal digital assistants (PDAs), mp3 players, mobile phones, videogame consoles, digital cameras, DVD players, GPS receivers, and printers. Many household appliances, such as microwave ovens, washing machines and dishwashers, are including embedded systems to provide flexibility, efficiency and features. Advanced HVAC systems use networked thermostats to more accurately and efficiently control temperature that can change by time of day and season. Home automation uses wired- and wireless-networking that can be used to control lights, climate, security, audio/visual, etc., all of which use embedded devices for sensing and controlling.

Transportation systems from flight to automobiles increasingly use embedded systems. New airplanes contain advanced avionics such as inertial guidance systems and GPS receivers that also have considerable safety requirements. Various electric motors — brushless DC motors, induction motors and DC motors — are using electric/electronic motor controllers. Automobiles, electric vehicles, and hybrid vehicles are increasingly using embedded systems to maximize efficiency and reduce pollution. Other automotive safety systems such as anti-lock braking system (ABS), Electronic Stability Control (ESC/ESP), traction control (TCS) and automatic four-wheel drive.

Medical equipment is continuing to advance with more embedded systems for vital signs monitoring, electronic stethoscopes for amplifying sounds, and various medical imaging (PET, SPECT, CT, MRI) for non-invasive internal inspections.



Characteristics

1. Embedded systems are designed to do some specific task, rather than be a general-purpose computer for multiple tasks. Some also have real-time performance constraints that must be met, for reasons such as safety and usability; others may have low or no performance requirements, allowing the system hardware to be simplified to reduce costs.

2. Embedded systems are not always standalone devices. Many embedded systems consist of small, computerized parts within a larger device that serves a more general purpose. For example, the Gibson Robot Guitar features an embedded system for tuning the strings, but the overall purpose of the Robot Guitar is, of course, to play music.Similarly, an embedded system in an automobile provides a specific function as a subsystem of the car itself.

3. The program instructions written for embedded systems are referred to as firmware, and are stored in read-only memory or Flash memory chips. They run with limited computer hardware resources: little memory, small or non-existent keyboard and/or screen.

Embedded software

Embedded software is computer software which plays an integral role in the electronics it is supplied with.

Embedded software's principal role is not Information Technology, but rather the interaction with the physical world. It's written for machines that are not, first and foremost, computers. Embedded software is 'built in' to the electronics in cars, telephones, audio equipment, robots, appliances, toys, security systems, pacemakers, televisions and digital watches, for example. This software can become very sophisticated in applications like airplanes, missiles, process control systems, and so on.

Embedded software is usually written for special purpose hardware: that is computer chips that are different from general purpose CPUs, sometimes using Real-time operating system such as LynxOS, VxWorks, Linux, eCos, ThreadX, Windows CE, Fusion RTOS, Nucleus RTOS, RTEMS, Integrity and Neutrino.

Programming Embedded Systems using C

Why using C?

- It is a 'mid-level', with 'high-level' features and 'low_level' features
- It is popular and very efficient
- Good, well-proven compilers are available for every embedded processor

The "super loop" software architecture

What is the minimum software environment you need to create an embedded C program?

Solution:



NOTE: 'Super loop' is required because there is no operating system to return to. The application will keep looping until the system power is removed.

One of the most fundamental differences between programs developed for embedded systems and those written for other computer platforms is that the embedded programs almost always have an infinite loop.

The infinite loop is necessary because the embedded software’s job is never done. It is intended to be run until either the world comes to an end or the board is reset, whichever happens first.

In addition, most embedded systems run only one piece of software. Although hardware is important, the system is not a digital watch or a cellular phone or a microwave oven without that software. If the software stops running, the hardware is rendered useless. So the functional parts of an embedded program are almost always surrounded by an infinite loop that ensures that they will run forever.

Writing Hardware specific code
In hardware specific code, we use hardware peripherals like ports, timers and uart etc. Do not forget to add header file for controller you are using, otherwise you will not be able to access registers related to peripherals.

Lets write a simple code to Blink LED on Port1, Pin1.

CODE:


Sunday, August 24, 2008

Sockets

Sockets

A socket is a bidirectional communication device that can be used to communicate with another process on the same machine or with a process running on other machines.

Sockets are the only interprocess communication that permit communication between processes on different computers. Internet programs such as Telnet, rlogin, FTP, talk, and the World Wide Web use sockets.

For example, you can obtain the WWW page from a Web server using the Telnet program because they both use sockets for network communications.

To open a connection to a WWW server at www.nidhish.co.nr, use
telnet
www.nidhish.co.nr 80.The magic constant 80 specifies
a connection to the Web server programming running
www.nidhish.co.nr instead of some other process.

Try typing GET / after the connection is established.This sends a message through the socket to the Web server, which replies by sending the home page’s HTML source and then closing the connection.

Networks

Most network application can be divided into two pieces: a client and a server. A client is the side that initiates the communication process, where as the server responds to incoming client requests.





There are numerous network protocols, such as Netbios, RPC (Remote Procedure Call), DCOM, Pipe, IPC (Inter-process Communication) that can be used for the Comm Link. We will only look at TCP/IP. In particular we will look at IPv4 since this is widely implemented by many socket vendors.

TCP Transmission Control Protocol

Although TCP can be implemented to work over any transport protocol, it's usually synonymous with IP. TCP is a connection -oriented stream protocol (like a telephone call). TCP communication happens using a handshake process, where each data that is sent is acknowledge by the recipient within the time of TCP’s timer value. TCP provides many services such as data reliability, error checking, and flow control. If a data packet is corrupt or lost (not acknowledged), TCP will retransmitted the data from the client side automatically. Because the route a packet takes can be many, one packet may arrive before the one sent earlier. As data packets arrive, it is the job of TCP to assemble the packets into the proper order. This is shown below with a factious network topology layout, where the data packet takes (n) number of hops to get from the source to the destination. On a bigger network like the Internet, there are many routes a data packet can take to arrive at its final destination.

Network Hop Topology




Byte Ordering

There are two types of memory byte ordering in use today that are very much machine dependent. They are known as little-endian and big-endian, because of this we have to be very careful how we interpret numerical data. If we do not take into account the endiannes, the numerical data we read will be corrupt.





When working with numeric data, one needs to convert from machine (host) byte order to network byte order when sending data (write-op), and then from network byte order to machine byte order when retrieving data (read-op). The APIs to make the conversion are:

htons()and htonl()
//host to network

uint16_t htons(uint16_t host16bitvalue);
uint32_t htonl(uint32_t host32bitvalue);


ntohs() and ntohl()
//network to host

uint16_t ntohs(uint16_t net16bitvalue);
unit32_t ntohl(unit32_t net32bitvalue);

Saturday, August 16, 2008

Thread Creation

Thread in a process is identified by a thread ID. When referring to thread IDs in C or C++ programs, use the type pthread_t. Each thread executes a thread function.

This is just an ordinary function and contains the code that the thread should run. When the function returns, the thread exits. The pthread_create function creates a new thread.

You provide it with the following:

1. A pointer to a pthread_t variable, in which the thread ID of the new thread is
stored.

2. A pointer to a thread attribute object.This object controls details of how the thread interacts with the rest of the program. If you pass NULL as the thread attribute, a thread will be created with the default thread attributes.

3. A pointer to the thread function.This is an ordinary function pointer, of this type: void* (*) (void*)

4. A thread argument value of type void*. Whatever you pass is simply passed as the argument to the thread function when the thread begins executing.


#include <pthread.h>
#include <stdio.h>


/* Prints x’s to stderr. The parameter is unused. Does not return. */

void* print_xs(void* unused)
{
while(1)
{
fputc (‘x’, stderr);
}
return NULL;
}

/* The main program. */
int main()
{
pthread_t thread_id;

/* Create a new thread. The new thread will run
the print_xs
function. */

pthread_create(&thread_id, NULL, &print_xs, NULL);

/* Print o’s continuously to stderr. */
while(1)
{
fputc(‘o’, stderr);
}

return 0;
}


Compile and link this program using the following code:

> cc -o thread-create thread-create.c -lpthread

Sunday, August 10, 2008

Inter-Process Communication (IPC) Methods






1. File
- (All operating systems)


A computer file is a block of arbitrary information, or resource for storing information, which is available to a computer program and is usually based on some kind of durable storage. A file is durable in the sense that it remains available for programs to use after the current program has finished. Computer files can be considered as the modern counterpart of paper documents which traditionally were kept in offices' and libraries' files, which are the source of the term.

2. Signal - (Most operating systems; some systems, such as Windows, only implement signals in the C run-time library and do not actually provide support for their use as an IPC technique)

A signal is a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems. Essentially it is an asynchronous notification sent to a process in order to notify it of an event that occurred. When a signal is sent to a process, the operating system interrupts the process' normal flow of execution. Execution can be interrupted during any non-atomic instruction. If the process has previously registered a signal handler, that routine is executed. Otherwise the default signal handler is executed.

3. Socket - (Most operating systems)

Sockets are just like "worm holes" in science fiction. When things go into one end, they (should) come out of the other. Different kinds of sockets have different properties. Sockets are either connection-oriented or connectionless. Connection-oriented sockets allow for data to flow back and forth as needed, while connectionless sockets (also known as datagram sockets) allow only one message at a time to be transmitted, without an open connection. There are also different socket families. The two most common are AF_INET for internet connections, and AF_UNIX for unix IPC (interprocess communication).

Of the various forms of IPC (Inter Process Communication), sockets are by far the most popular. On any given platform, there are likely to be other forms of IPC that are faster, but for cross-platform communication, sockets are about the only game in town.

4. Pipe - (All POSIX systems)

In Unix-like computer operating systems, a pipeline is the original software pipeline: a set of processes chained by their standard streams, so that the output of each process (stdout) feeds directly as input (stdin) of the next one. Each connection is implemented by an anonymous pipe. Filter programs are often used in this configuration.

5. Named pipe - (All POSIX systems)

In computing, a named pipe (also FIFO for its behavior) is an extension to the traditional pipe concept on Unix and Unix-like systems, and is one of the methods of inter-process communication. The concept is also found in Microsoft Windows, although the semantics differ substantially. A traditional pipe is "unnamed" because it exists anonymously and persists only for as long as the process is running. A named pipe is system-persistent and exists beyond the life of the process and must be "unlinked" or deleted once it is no longer being used. Processes generally attach to the named pipe (usually appearing as a file) to perform IPC (inter-process communication).

6. Semaphore - (All POSIX systems)

A semaphore is nothing but a term used in UNIX for a variable which acts as a counter. So the next question that comes in mind is what for we need this variable. It’s so simple.

For instance there may be times when two processes try to access the same file simultaneously. In this event we must control the access of the file when the other process is accessing. This is done by assigning value to semaphore.

A semaphore, in computer science, is a protected variable (an entity storing a value) or abstract data type (an entity grouping several variables that may or may not be numerical) which constitutes the classic method for restricting access to shared resources, such as shared memory, in a multiprogramming environment (a system where several programs may be executing, or taking turns to execute, at once).

Semaphores exist in many variants, though usually the term refers to a counting semaphore, since a binary semaphore is better known as a mutex. A counting semaphore is a counter for a set of available resources, rather than a locked/unlocked flag of a single resource.

Semaphores are the classic solution to preventing race conditions in the dining philosophers problem, although they do not prevent resource deadlocks.


7. Shared memory - (All POSIX systems)

What is Shared Memory?

Shared Memory is an efficient means of passing data between programs. One program will create a memory portion which other processes (if permitted) can access. Shared memory is another method of interprocess communication (IPC) whereby 2 or more processes share a single chunk of memory to communicate. The shared memory system can also be used to set permissions on memory, allowing for things like malloc debuggers to be written.



Types of Shared memory available

Basically there are two different types of shared memory available for most flavors of UNIX. As you may have guessed, each of the two original ancestors of modern UNIX have their own implementation, although almost all modern UNIX flavors implement both. The names of the respective implementations are System V IPC, and BSD mmap.

8. Message queue - (Most operating systems)

In computer science, a message queue is a software-engineering component used for interprocess communication or inter-thread communication within the same process. It uses a queue for messaging – the passing of control or of content. Group communication systems provide similar kinds of functionality.









Message queues provide an asynchronous communications protocol, meaning that the sender and receiver of the message do not need to interact with the message queue at the same time. Messages placed onto the queue are stored until the recipient retrieves them.

Examples of commercial implementations of this kind of message queueing software (also known as Message Oriented Middleware) include IBM's WebSphere MQ (formerly MQ Series), Oracle Advanced Queuing (AQ) within an Oracle database, and Microsoft's MSMQ. There is a Java standard called Java Message Service, which has, associated with it, a number of implementations, both proprietary and free software.

Synchronous vs. asynchronous

Many of the more widely-known communications protocols in use operate synchronously. The HTTP protocol – used in the World Wide Web and in web services – offers an obvious example.

In a synchronous model, one system makes a connection to another, sends a request and waits for a reply.



Inter-Process Communication (IPC) in Unix






Inter-Process Communication
(IPC) is a set of techniques for the exchange of data among two or more threads in one or more processes. Processes may be running on one or more computers connected by a network. IPC techniques are divided into methods for message passing, synchronization, shared memory, and remote procedure calls (RPC). The method of IPC used may vary based on the bandwidth and latency of communication between the threads, and the type of data being communicated.

IPC may also be referred to as inter-thread communication and inter-application communication.

Friday, August 8, 2008

Wednesday, August 6, 2008

What is a UNIX Process






What is a UNIX Process

A process is an instance of a computer program that is being sequentially executed by a computer system that has the ability to run several computer programs concurrently.

Unix Process

An entity that executes a given piece of code, has its own execution stack, its own set of memory pages, its own file descriptors table, and a unique process ID.

The fork() system call

The fork() system call is the basic way to create a new process. It is also a very unique system call, since it returns twice(!) to the caller.

Example:


#include <unistd.h>
#include <sys/wait.h>

pid_t child_pid;
int child_status;

/* lets fork off a child process... */
child_pid = fork();

/* check what the fork() call actually did */
switch (child_pid) {
case -1: /* fork() failed */
perror("fork"); /* print a system-defined error message */
exit(1);
case 0: /* fork() succeeded, we're inside the child process */

printf("Hello, World\n");
exit(0); /* here the CHILD process exits, not the parent. */
default: /* fork() succeeded, we're inside the parent process */
wait(&child_status); /* wait till the child process exits */
}
/* parent's process code may continue here... */

Notes:

* The perror() function prints an error message based on the value of the errno variable, to stderr.

* The wait() system call waits until any child process exits, and stores its exit status in the variable supplied. There are a set of macros to check this status, that will be explained in the next section.

Thread - a thread of execution





What are threads?


A thread is a sequence of instructions to be executed within
a program. Normal UNIX processes consist of a single thread
of execution that starts in main(). In other words, each line
of your code is executed in turn, exactly one line at a time.
Before threads, the normal way to achieve multiple
instruction sequences (ie, doing several things at once, in
parallel) was to use the fork() and exec() system calls to
create several processes -- each being a single thread of
execution.

In the UNIX operating system, every process has the following:

1. a virtual address space (ie, stack, data, and code segments)

2. system resources (eg, open files)

3. a thread of execution

These resources are private to each process; for example, processes
cannot peek into one another's address space, open and close
files for one another, etc.



Monday, August 4, 2008

C++ program - Hello World!






Program 2. C++ source file—main.cpp

#include <iostream>
using namespace std;

int main()
{
cout << "Hello World!" << endl;
}

The main function serves a special purpose in C++ programs:

* The run-time environment calls the main function to begin
program execution.

* The opening curly brace indicates the beginning of the
definition of the main function.

* To print a value to the screen, write the word cout, followed by the insertion operator (<<), which you create by typing the less-than character (<) twice. Even though this is two characters, C++ treats it as one.

* A commonly-used alternative to the newline character \n is endl

* The return statement terminates the execution of the main
function and causes it to return the integer value 0, which is
interpreted by the run-time system as an exit code indicating
successful execution.

* The closing curly brace indicates the end of the code for
the main function.

Compiling a single C++ source file:

The C++ compiler is called g++.

> g++ main.cpp -o main.cpp.o


Output: