EmbLogic's Blog

message queue log file

Log File For Server:

head    1.2;
access;
symbols;
locks
root:1.2; strict;
comment    @ * @;

1.2
date    2013.12.24.10.09.27;    author root;    state Exp;
branches;
next    1.1;

1.1
date    2013.12.24.09.32.25;    author root;    state Exp;
branches;
next    ;

desc
@This is the main server source file for client server project using message queue.
@

1.2
log
@This is the final source code of server.
change the value of msg_id of msg_st.
————————————————————————————————

Log File For Req_add
head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.09.38.26;    author root;    state Exp;
branches;
next    ;

desc
@This is the request client for addition.
@

1.1
log
@Initial revision

 

—————————————————————————————-

Log file for Req_sub

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.06.30;    author root;    state Exp;
branches;
next    ;

desc
@This is the source code of requesting client for substration.
@

1.1
log
@Initial revision

 

—————————————————————————————-

log file for Req_Mul

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.07.13;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of requesting client for multiplication.
@

1.1
log
@Initial revision

—————————————————————————————

Log file For Proccesing_Add

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.09.54.10;    author root;    state Exp;
branches;
next    ;

desc
@This is the source code of processing client for addition.
@

1.1
log
@Initial revision

—————————————————————————————

Log file For Proccesing_Sub

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.08.22;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of processing client for substraction.
@

1.1
log
@Initial revision

—————————————————————————————

Log file For Proccesing_Mul

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.09.14;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of processing client for multiplcation.
@

1.1
log
@Initial revision

Posted in Uncategorized | Leave a comment

Server-Client Communication using Message Queues Completed

Log File For Server:

head    1.2;
access;
symbols;
locks
root:1.2; strict;
comment    @ * @;

1.2
date    2013.12.24.10.09.27;    author root;    state Exp;
branches;
next    1.1;

1.1
date    2013.12.24.09.32.25;    author root;    state Exp;
branches;
next    ;

desc
@This is the main server source file for client server project using message queue.
@

1.2
log
@This is the final source code of server.
change the value of msg_id of msg_st.
————————————————————————————————

Log File For Req_add
head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.09.38.26;    author root;    state Exp;
branches;
next    ;

desc
@This is the request client for addition.
@

1.1
log
@Initial revision

 

—————————————————————————————-

Log file for Req_sub

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.06.30;    author root;    state Exp;
branches;
next    ;

desc
@This is the source code of requesting client for substration.
@

1.1
log
@Initial revision

 

—————————————————————————————-

log file for Req_Mul

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.07.13;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of requesting client for multiplication.
@

1.1
log
@Initial revision

—————————————————————————————

Log file For Proccesing_Add

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.09.54.10;    author root;    state Exp;
branches;
next    ;

desc
@This is the source code of processing client for addition.
@

1.1
log
@Initial revision

—————————————————————————————

Log file For Proccesing_Sub

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.08.22;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of processing client for substraction.
@

1.1
log
@Initial revision

—————————————————————————————

Log file For Proccesing_Mul

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.09.14;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of processing client for multiplcation.
@

1.1
log
@Initial revision

—————————————————————————————

Posted in Project 03: Client Server Communication using Linux and IPC | Tagged , | Leave a comment

IPC using mesaage queues.

Implemented the Inter process communication using message queues and the project is completed for 3 requesting and 3 processing clients.

Log file of Server:

head    1.2;
access;
symbols;
locks
root:1.2; strict;
comment    @ * @;

1.2
date    2013.12.24.10.09.27;    author root;    state Exp;
branches;
next    1.1;

1.1
date    2013.12.24.09.32.25;    author root;    state Exp;
branches;
next    ;

desc
@This is the main server source file for client server project using message queue.
@

1.2
log
@This is the final source code of server.
change the value of msg_id of msg_st.
@

Log file of requesting clients:

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.09.38.26;    author root;    state Exp;
branches;
next    ;

desc
@This is the request client for addition.
@

1.1
log
@Initial revision
@

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.07.13;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of requesting client for multiplication.
@

1.1
log
@Initial revision
@

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.06.30;    author root;    state Exp;
branches;
next    ;

desc
@This is the source code of requesting client for substration.
@

1.1
log
@Initial revision
@

Log file for processing client:

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.09.54.10;    author root;    state Exp;
branches;
next    ;

desc
@This is the source code of processing client for addition.
@

1.1
log
@Initial revision
@

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.09.14;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of processing client for multiplcation.
@

1.1
log
@Initial revision
@

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2013.12.24.10.08.22;    author root;    state Exp;
branches;
next    ;

desc
@This is source code of processing client for substraction.
@

1.1
log
@Initial revision
@

Posted in Uncategorized | Leave a comment

IPCs

INTER-PROCESS COMMNICATION

What is Inter-process Communication?

Inter-process communication as the name suggests is the exchange of information between two dependent /independent processes.

 

Why it is required?

There are cases when processes may need to work together;for example a process may need to compress an image that is to be performed by some other process,in that case the first process must tell the second process that it needs its services and hence send image and receive the compressed image. Thus the requirement of inter-process communication.

 

How inter-process communication is needed?

In Linux,inter-process communication is achieved using:-

->Signals

->Pipes

->FIFO’s

->Message queues

->Shared memory

->Semaphores

Signals,Shared memory and Message queues are mostly used as synchronization techniques rather than as Inter-process Communication mechanism.

 

Project Implementation:-

Aim:-To achieve inter-process communication between multiple client(requesting and processing) processes and a single server using Inter-process communication techniques.

 

Explanation:-

In this project multiple requesting clients requests a server process to get their respective results

Requesting Client 1———->S V————->Processing Client 1

Requesting Client 2———->E E————->Processing Client 2

Requesting Client 3———->R R————>Processing Client 3

 

Server is always runing in the background.

Firstly requesting client requests the server by sending the data along with the data it wants to get performed.

Next the server receives the request and it sends the same request to the processing client.

Now the processing client processes the data and should return the result to the server.

Meanwhile the procesing client is processing the request, the requesting client and the server should wait.

After the processing client sends the result to the server,the server sends the result to the requesting client.

There can be many requesting clients thus the server should be prepared for it.

 

Implementation:-

The project was implemented using Pipes,FIFOs and Pipes,Message queues, FIFOs and shared memory and FIFOs and message queues.

Challenges:-

->The major challenge during the project implementation was the synchronization between the requesting client and the server And server and processing client.

When implemented using pipes,synchronization was acheived using the signals mechanism. The requesting clients after sending the request waits for a signal from the server indicating that result is available.

At the same time the server waits for the result from processing client using signal.

In case of implementation using FIFOs and pipes,synchronization was acheived using signals.

For message queues,synchronization was acheived using the tokens only.

And semaphores were used for the other implementations of the same project.

 

->The next challenge was the encapsulating of the requests and the results into a single packet that would be exchanges between the processes. Since request consisted of many things,they were converted to a single packet of data using sprintf() function.

Same method was used for the result.

 

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

SEMAPHORE PROGRAMING

In computer science, particularly in operating systems, a semaphore is a variable or abstract data type that is used for controlling access, by multiple processes, to a common resource in a parallel programming or a multi userenvironment.

Semantics and implementation

Counting semaphores are equipped with two operations, historically denoted as V (also known as signal()) and P (or wait())(see below). Operation V increments the semaphore S, and operation P decrements it. The semantics of these operations are shown below. Square brackets are used to indicate atomic operations, i.e., operations which appear indivisible from the perspective of other processes.

The value of the semaphore S is the number of units of the resource that are currently available. The P operation wastes time or sleeps until a resource protected by the semaphore becomes available, at which time the resource is immediately claimed. The V operation is the inverse: it makes a resource available again after the process has finished using it. One important property of semaphore S is that its value cannot be changed except by using the V signal() and P wait() operations.

A simple way to understand wait() and signal() operations is:

  • wait(): Decrements the value of semaphore variable by 1. If the value becomes negative, the process executing wait() is blocked, i.e., added to the semaphore’s queue.
  • signal(): Increments the value of semaphore variable by 1. After the increment, if the pre-increment value was negative (meaning there are processes waiting for a resource), it transfers a blocked process from the semaphore’s waiting queue to the ready queue.

Many operating systems provide efficient semaphore primitives that unblock a waiting process when the semaphore is incremented. This means that processes do not waste time checking the semaphore value unnecessarily.

 

Posted in Uncategorized | Leave a comment

Interrupt and IRQ

To understand Interrupts in a general context, we can say that the Interrupts behaves same as the Signals for user space applications.
Two Types of interrupts can be generated ? one is generated by the Processor control unit while executing the instructions and the other one is generated by the other hardware device and generally called as the hardware interrupts.
As the processor receives an Interrupt, the processor stops its normal execution of the instructions and switches to the different context other than the normal process context. This code (Interrupt handler) for this context is written specially for the particular Interrupt. The interrupt handling is quite different from the process context switching. But after the execution of the interrupt handler the last process resumes to the execution.
Interrupt Handler function must not contain the sleep. Interrupt handler must execute in the minimum possible amount of time. If there is some task which as to be implemented as the interrupt arrives and this task requires some time to execute, then the code for this must be written in the bottom half. Workqueue or Softirq can be implemented in the bottom half. This should be done because while interrupt handler is running, the signals on the corresponding IRQ line are temporarily disabled. The handler also sends the acknowledgment to the Programmable Interrupt Controller that I am servicing the interrupt.
IRQ (a kernel identifier) is a interrupt request from a device. During the execution of interrupt handler for a particular IRQ, the interrupt is disabled for that IRQ. Kernel also provides the facility to disable all interrupts issued by IRQ by a function. IRQ number provides the possible interrupt source on a machine.
Most hardware controller are capable of issuing interrupt requests and these interrupt requests are fed to the Programmable Interrupt Controller. The Programmable Interrupt Controller is responsible for monitoring the IRQ lines and to inform the processor on the INTR pin of the processor.
Several devices may share the same IRQ line and the most important thing that the kernel has to discover which I/O device corresponds to the particular IRQ number before enabling the Interrupt.
The interrupt handler executes several Interrupt Service Routines. Each Interrupt Service routine is a function related to a single device sharing the IRQ lines. Hence the IRQ lines can be shared among different devices and the meaning of IRQ line becomes different for each IRQ line. The Interrupt Service Routine performs all operations that need to be executed when the device raise the interrupt. Most of the time Interrupt is  best way to avoid the polling mechanism. It is helpful to save the CPU cycles. There are priority mechanism among different interrupts.
When the device driver’s interrupt handling routine is called by the Linux kernel it must efficiently work out why it was interrupted and respond. To find the cause of the interrupt the device driver should read the status register of the device that interrupted. Hence Interrupts are mostly used in the device drivers.

Posted in Uncategorized | Leave a comment

Linked list implementation….

RCS file: linked_list.c,v
Working file: linked_list.c
head: 1.7
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 7;	selected revisions: 7
description:
linked list creation is done successfully.
The number of nodes in the linked list is 1 having the value 10.
----------------------------
revision 1.7
date: 2013/12/21 01:41:21;  author: root;  state: Exp;  lines: +2 -2
Linked list with any number of nodes is created.
Deletion of nodes is also implemented and is working is checked.
The definition of function to sort the info is made.
And is in the process.....
----------------------------
revision 1.6
date: 2013/12/20 19:08:49;  author: root;  state: Exp;  lines: +1 -0
Previously sort function is not working properly.
Logical error present.
Checking.
----------------------------
revision 1.5
date: 2013/12/20 18:56:31;  author: root;  state: Exp;  lines: +31 -2
Definition for sorting a linked a list is done.
Checking whether it is working or not.
----------------------------
revision 1.4
date: 2013/12/20 18:33:44;  author: root;  state: Exp;  lines: +80 -24
Insert at the beginning of the linked list is implemented.
----------------------------
revision 1.3
date: 2013/12/17 13:30:51;  author: root;  state: Exp;  lines: +30 -9
Display function is implemented.
And corrections are made in the inser_node() functon.
----------------------------
revision 1.2
date: 2013/12/14 19:37:01;  author: root;  state: Exp;  lines: +10 -1
Created a definition of insert_node() but link is not created.
----------------------------
revision 1.1
date: 2013/12/13 20:35:10;  author: root;  state: Exp;
Initial revision
=============================================================================
Posted in Data Structures with C | Leave a comment

Stack implementation using Linked lists

RCS file: stack_using_linked_list.c,v
Working file: stack_using_linked_list.c
head: 1.3
branch:
locks: strict
	root: 1.3
access list:
symbolic names:
keyword substitution: kv
total revisions: 3;	selected revisions: 3
description:
Implementing stack using linked list.
Push,pop and display operations are implemented using functions.
----------------------------
revision 1.3	locked by: root;
date: 2013/12/21 01:15:23;  author: root;  state: Exp;  lines: +36 -7
The program is further optimised.
----------------------------
revision 1.2
date: 2013/12/18 01:09:50;  author: root;  state: Exp;  lines: +4 -5
Push operation is implemented is successfully.
Display function is working correctly.
----------------------------
revision 1.1
date: 2013/12/18 00:50:07;  author: root;  state: Exp;
Initial revision
=============================================================================
Posted in Data Structures with C | Leave a comment

PIPES

Piping is a process where the output of one process is made the input of another.In numerous applications there is clearly a need for these processes to communicate with each exchanging data or control information.

Pipes can be used in threads and processes. A new process can be created using the system call fork(). It returns two differnt values to the child and parent. The value 0 is returned to the child (new) process and the PID (Process ID) of the child is returned to the parent process. This is used to distinguish between the two processes. In the program given below, the child process waits for the user input and once an input is entered, it writes into the pipe. And the parent process reads from the pipe.

the pipe() system call was called before the system call fork().the pipe has been set up, two (or more) cooperative processes will be created by a fork and data will be passed using read() and write(). Pipes opened with pipe() should be closed with close(int fd).

note:

1)pipe is always declared before fork.

2)switching is starts just after fork.for example

pid1=fork();
switch(pid1)
{
case 0:—.

case1:—.

}

3)if you are not using semaphore there will be some synchrosing error you can remove that using sleep and wait statements.

4)we can use sscanf()and sprintf() for converting string to variable and variable to string respectively.

5)In pipes ,by the use of command line argument(run time argument) for communication between server and client.

 

Posted in Uncategorized | Leave a comment

Pipe(a brief introduction)

What is pipe in our day to day life?

Pipe is basically a connector to send any thing from one place to another.

It has same meaning in Linux C. We create pipe to connect data flow from one process to another. It is a very paramount aspect of IPC – Inter Process Communication.Pipe is half duplex.

To create a simple pipe with C, we make use of the pipe() system call. It takes a single argument, which is an array of two integers, and if successful, the array will contain two new file descriptors to be used for the pipeline.

the prototype of pipe function is:

#include<unistd.h>

int pipe(int fd[2]);

After creating a pipe, the process typically spawns a new process . The first integer in the array (element 0) is set up and opened for reading, while the second integer (element 1) is set up and opened for writing. Once we have established the pipeline, we then fork our new child process:

If the parent wants to receive data from the child, it should close fd1, and the child should close fd0. If the parent wants to send data to the child, it should close fd0, and the child should close fd1. Since descriptors are shared between the parent and child, we should always be sure to close the end of pipe we aren’t concerned with. On a technical note, the EOF will never be returned if the unnecessary ends of the pipe are not explicitly closed.

The real advantage of pipe is when you wish to pass data between two processes which have any ancestoral relation.

Posted in Uncategorized | Leave a comment

Client Server setup using Pipes….

For making a client server set up, you need to know how a child process create by parent process. A parent process makes a child process by using fork() system call.

Fork (system call):-

fork is an operation whereby a process creates a copy of itself. It is usually a system call, implemented in the kernal. Fork is the primary (and historically, only) method of process creation on Unix-like operating systems.fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent. Fork() system call makes a child process and return child’s pid(pid means unique process id).

Now next you have to make pipe between the client and server for communication between them.

Pipes:-

A pipe is medium to communicate between processes which have something common between them. A pipe is created by pipe(int arr[2]) whose argument is an integer type of array which stores 2 descriptors(one for read and one for write). Data can be write and read from pipe through these descriptors.

Posted in Uncategorized | Leave a comment

Python

Python is a general-purpose interpreted, interactive, object-oriented ,Platfom independent and high-level programming language. Python was created by Guido van Rossum in the late eighties and early nineties. Python source code is also now available under the GNU General Public License (GPL).

Python is Interpreted: This means that it is processed at run time by the interpreter and we do not need to compile our program before executing it.

Python is Interactive: This means that we can actually work at python prompt and interact with the interpreter directly to write our programs.

Python is Object-Oriented: This means that Python supports Object-Oriented style or technique of programming that encapsulates code within objects.

Python has support for functional and structured programming methods as well as OOP. It can be used as a scripting language or can be compiled to byte-code for building large applications. It has very high-level dynamic data types and supports dynamic type checking. It supports automatic garbage collection.

Programming in Python

Python program can run on any operating system since it is platform independent language.

There are three different ways to work in Python :

  1. Interactive mode : We can enter python’s interactive mode by “python” in command line and write our commands.

  2. Script from command line : We can first make a script using an editor e.g. Vim editor with extention ‘.py’ (e.g. Hello.py) and then run this script using command ‘python hello.py’ ( hello.py being the script name) .

  3. Integrated Development Environment : We can use an IDE for python programming . IDE used in UNIX is IDLE.

Data types

Python has five standard data types :

  1. Numbers : Includes signed integers, long integers , float and complex numbers .

  2. Strings

  3. List

  4. Tuple

  5. Dictionary

Operators

Like all other languages python supports a number of operators . These are :

  1. Arithmetic operators

  2. Comparison (i.e., Relational) Operators

  3. Assignment Operators

  4. Logical Operators

  5. Bitwise Operators

  6. Membership Operators (in , not in)

  7. Identity Operators (is , is not)

Posted in Uncategorized | Leave a comment

Basic Signal Programming

Basic Signal Programming
1
What is a signal?
Signals are generated when an event occurs
that requires attention. It can be considered as
a software version of a hardware interrupt
Signal Sources:
Hardware – division by zero
Kernel – notifying an I/O device for which a process
has been waiting is available
Other Processes – a child notifies its parent that it
has terminated
User – key press (i.e., Ctrl-C)
2
What signals are available?
Signal names are defined in signal.h
The following are examples:
SIGALRM – alarm clock
SIGBUS – bus error
SIGFPE – floating point arithmetic exception
SIGINT – interrupt (i.e., Ctrl-C)
SIGQUIT – quit (i.e., Ctrl-\)
SIGTERM – process terminated
SIGUSR1 and SIGUSR2 – user defined signals
You can ignore some signals
You can also catch and handle some signals.
3
Signal Sources
4
Function signal()
void (*signal(int, void (*)(int)))(int);
signal() is a function that accepts two arguments
and returns a pointer to a function that takes one
argument, the signal handler, and returns nothing.
If the call fails, it returns SIG_ERR.
The arguments are
The first is an integer (i.e., int), a signal name.
The second is a function that accepts an int argument
and returns nothing, the signal handler.
If you want to ignore a signal, use SIG_IGN as the second
argument.
If you want to use the default way to handle a signal, use
SIG_DFL as the second argument.
5
Examples
The following ignores signal SIGINT
signal(SIGINT, SIG_IGN);
The following uses the default way to handle
SIGALRM
signal(SIGALRM, SIG_DFL);
The following installs function INThandler()
as the signal handler for signal SIGINT
signal(SIGINT, INThandler);
6
Install a Signal Handler: 1/2
#include
#include
void
INThandler(int);
void main(void)
{
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
signal(SIGINT, INThandler);
while (1)
pause();
}
7
Install a Signal Handler: 2/2
void INThandler(int sig)
ignore the signal first
{
char c;
signal(sig, SIG_IGN);
printf(“Ouch, did you hit Ctrl-C?\n”,
“Do you really want to quit [y/n]?”);
c = getchar();
if (c == ‘y’ || c = ‘Y’)
exit(0);
else
signal(SIGINT, INThandler);
}
8
reinstall the signal handler
Here is the procedure
1. Prepare a function that accepts an integer, a
signal name, to be a signal handler.
2. Call signal() with a signal name as the first
argument and the signal handler as the second.
3. When the signal you want to handle occurs,
your signal handler is called with the argument
the signal name that just occurred.
4. Two important notes:
a. You might want to ignore that signal in your handler
b. Before returning from your signal handler, don’t
forget to re-install it.
9
Handling Multiple Signal Types: 1/2
You can install multiple signal handlers:
signal(SIGINT, INThandler);
signal(SIGQUIT, QUIThandler);
void INThandler(int sig)
{
// SIGINT handler code
}
void QUIThandler(int sig)
{
// SIGQUIT handler code
}
10
Handling Multiple Signal Types: 2/2
Or, you can use one signal handler and install it
multiple times
signal(SIGINT, SIGhandler);
signal(SIGQUIT, SIGhandler);
void SIGhandler(int sig)
{
switch (sig) {
case SIGINT:
// code for SIGINT
case SIGQUIT: // code for SIGQUIT
default:
// other signal types
}
}
11
Handling Multiple Signal Types
Example: 1/4
#include
#include
#include
#define
#define
#define
MAX_i
MAX_j
MAX_SECOND
10000
20000
(2)
void INThandler(int);
void ALARMhandler(int);
int SECOND, i, j
12
Handling Multiple Signal Types
Example: 2/4
void INThandler(int sig)
{
char c;
signal(SIGINT, SIG_IGN);
signal(SIGALRM, SIG_IGN);
printf(“INT handler: i = %d and j = %d\n”, i, j);
printf(“INT handler: want to quit [y/n]?”);
c = tolower(getchar());
if (c == ‘y’) {
printf(“INT handler: done”); exit(0);
}
signal(SIGINT, INThandler);
signal(SIGALRM, ALARMhandler);
alarm(SECOND);
}
13
This is a Unix system call
Handling Multiple Signal Types
Example: 3/4
void ALARMhandler(int sig)
{
signal(SIGINT, SIG_IGN);
signal(SIGALRM, SIG_IGN);
printf(“ALARM handler: alarm signal received\n”);
printf(“ALARM handler: i = %d and j = %d\n”, i, j);
alarm(SECOND);
signal(SIGINT, INThandler);
signal(SIGALRM, ALARMhandler);
}
set alarm clock to SECOND seconds
14
Handling Multiple Signal Types
Example: 4/4
void main(int argc, char *argv[])
{
long sum;
SECOND = abs(atoi(argv[1]));
signal(SIGINT, INThandler);
signal(SIGALRM, ALARMhandler);
alarm(SECOND);
for (i = 1; i <= MAX_i, i_++) {
sum = 0;
for (j = 1; j <= MAX_j; j++)
sum += j;
}
printf(“Computation is done.\n\n”);
}
15
Raise a Signal within a Process: 1/2
Use ANSI C function raise() to “raise” a signal
int raise(int sig);
Raise() returns non-zero if unsuccessful.
#include
#include
long
Check here if it is a SIGUSR1!
pre_fact, i;
void SIGhandler(int);
void SIGhandler(int sig)
{
printf(“\nReceived a SIGUSR1 signal %ld! = %ld\n”,
i-1, pre_fact);
}
16
Raise a Signal within a Process: 2/2
void main(void)
{
long fact;
signal(SIGUSR1, SIGhandler);
for (prev_fact=i=1; ; i++, prev_fact = fact) {
fact = prev_fact * i;
if (fact < 0)
raise(SIGUSR1);
else if (i % 3 == 0)
printf(“
%ld = %ld\n”, i, fact);
}
}
Assuming an integer overflow will wrap around!
17
Send a Signal to a Process
Use Unix system call kill() to send a signal
to another process:
int kill(pid_t pid, int sig);
kill() sends the sig signal to process with
ID pid.
So, you must find some way to know the
process ID of the process a signal is sent to.
18
Kill Example: process-a (1)
#include
#include
#include
#include
#include

void SIGINT_handler(int);
void SIGQUIT_handler(int);
int
pid_t
ShmID;
*ShmPTR;
used to save shared memory ID
my PID will be stored here
19
Kill Example: process-a (2)
void main(void)
{
int
i;
pid_t pid = getpid();
key_y MyKey;
signal(SIGINT, SIGINT_handler);
signal(SIGQUIT, SIGQUIT_handler);
MyKey = ftok(“./”, ‘a’);
ShmID = shmget(MyKey, sizeof(pid_t), IPC_CREAT|0666);
ShmPTR = (pid_t *) shmat(shmID, NULL, 0);
*ShmPTR = pid;
for (i = 0; ; i++) {
printf(“From process %d: %d\n”, pid, i);
sleep(1);
}
}
20
Kill Example: process-a (2)
use Ctrl-C to interrupt
void SIGINT_handler(int sig)
{
signal(sig, SIG_IGN);
printf(“From SIGINT: got a Ctrl-C signal %d\n”, sig);
signal(sig, SIGINT_handler);
}
void SIGQUIT_handler(int sig) use Ctrl-\ to kill this program
{
signal(sig, SIG_IGN);
printf(“From SIGQUIT: got a Ctrl-\\ signal %d\n”, sig);
printf(“From SIGQUIT: quitting\n”);
shmdt(ShmPTR);
shmctl(ShmID, IPC_RMID, NULL);
exit(0);
}
21
Kill Example: process-b (1)
#include
#include
#include
#include
#include

Void main(void)
{
pid_t pid, *ShmPTR;
key_t MyKey;
int
ShmID;
char
c;
detach the shared memory
after taking the pid
MyKey = ftok(“./”, ‘a’);
ShmID = shmget(MyKey, sizeof(pid_t), 0666);
ShmPTR = (pid_t *) shmat(ShmID, NULL, 0);
pid
= *ShmPTR;
shmdt(ShmPTR); /* see next page */
22
Kill Example: process-b (2)
while (1) {
printf(“(i for interrupt or k for kill)? ”);
c = getchar();
if (c == ‘i’ || c == ‘I’) {
kill(pid, SIGINT);
printf(“A SIGKILL signal has been sent\n”);
}
else if (c == ‘k’ || c == ‘K’) {
printf(“About to sent a SIGQUIT signal\n”);
kill(pid, SIGQUIT);
exit(0);
}
else
printf(“Wrong keypress (%c). Try again!\n”, c);
}
}
23
You can kill process-a from within process-b!
The Unix Kill Command
The kill command can also be used to send a signal
to a process:
kill –l /* list all signals */
kill –XXX pid1 pid …… pid
In the above XXX is the signal name without the
initial letters SIG.
kill –KILL 1357 2468 kills process 1357 and
2468.
kill –INT 6421 sends a SIGINT to process 6421.
A kill without a signal name is equivalent to
SIGTERM.
-9 is equal to –SIGKILL.
24

Posted in Uncategorized | Leave a comment

Python

Python is a very simple language, and has a very straightforward syntax. It encourages programmers to program without prepared code. The simplest directive in Python is the “print” directive – it simply prints out a line and also includes a newline, unlike in C

There are two major Python versions, Python 2 and Python 3. Python 2 and 3 are quite different. This tutorial uses Python 2, because it is more widely used and supported.

 To print a string, just write:

print "hello"

Indentation

Python uses indentation for blocks, instead of curly braces. Both tabs and spaces are supported, but the standard indentation requires standard Python code to use four spaces. For example:

x = 1

      if x == 1: # tab for indentation print "x is 1." this print statement belongs to the block of above specified if block and every statement written after indentation will come inside the “if” block.

Variables and Types

Python is completely object oriented. You do not need to declare variables before using them, or declare their type. Every variable in Python is an object.

5 major variable in python

Numbers

Python supports two types of numbers – integers and floating point numbers. (It also supports complex numbers,

To define an integer, use the following syntax:

myint = 7 To define a floating point number, you may use one of the following notations: myfloat = 7.0

Strings

Strings are defined either with a single quote or a double quotes.

mystring = 'hello' mystring = "hello"

Lists

Lists are very similar to arrays. They can contain any type of variable, and they can contain as many variables as you wish. Lists can also be iterated over in a very simple manner. The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets. Good thing about a list is that items in a list need not all have the same type.

mylist = [“hello”,123]

Tuples

A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The only difference is that tuples can't be changed i.e., tuples are immutable and tuples use parentheses and lists use square brackets.

Creating a tuple is as simple as putting different comma-separated values and optionally you can put these comma-separated values between parentheses also. For example:

tup=(“hello”,123)

Dictionaries

A dictionary is mutable and is another container type that can store any number of Python objects, including other container types. Dictionaries consist of pairs (called items) of keys and their corresponding values.

Python dictionaries are also known as associative arrays or hash tables. The general syntax of a dictionary is as follows:

dict = {“name” : “xyz” , “age” : “123”}

Posted in Uncategorized | Leave a comment

H264 vedio Compression

H.264 as video coding algorithm is important for broadcasting standards such as DVB-H and DMB. In comparison to its predecessors MPEG-2 and MEPG-4 SP/ASP, H.264 achieves improved compression efficiency at the cost of increased computational complexity. Real-time execution of the H.264 decoding process poses a large challenge on mobile devices due to low processing capabilities. Multi -core systems provide an elegant and power-efficient solution to overcome this performance limitation. However, efficiently distributing the video algorithm among multiple processing units is a non-trivial task. It requires detailed knowledge about the algorithmic complexity, dynamic variations and inter-dependencies between functional blocks of multi-core environments.

H.264/MPEG-4 AVC is a block-oriented motion- compensation -based codec standard .CONTEXT-BASED adaptive binary arithmetic coding (CABAC) used in H.264/AVC , is an extension of the binary arithmetic coding (BAC), where the coding offset value is dynamically adjusted based on the syntax element being encoded/decoded. While the coding efficiency of CABAC is superior to the conventional Huffman coding , the improvement comes with an increasing performance requirement; at least 3 GHz of computing power is required for the real-time decoding of a HD sequence if a general-purpose,yet high-speed, RISC machine processes the syntax parsing.As HD digital TV broadcasting coded in H.264/AVC Main Profile and High Profile is being widely spread at the present,the necessity of a high-speed CABAC decoder is growing

The gained insights are finally used to optimize the run time behavior of a multi-core decoding system and to find a good trade-off between core usage and buffer sizes.

Increasing the coding efficiency of video codecs with the common combination of temporal prediction and lossy transform coding is basically a matter of reducing the remaining redundancy in the data streams. In H.264 standard, this goal has been achieved by means of more advanced pixel processing algorithms (eg 1/4-pixel motion estimation)as well as using more sophisticated algorithms for predicting syntax elements from neighboring macro blocks (eg context adaptive VLC). However, the advanced coding tools result in significantly increased CPU and memory loads on encoder as well as the decoder. The high computational demands pose a challenge for practical H.264 implementations in environments of limited processing power such as mobile devices. Understanding the run time behavior of the H.264 decoder is therefore essential for meeting the desired performance requirements on the underlying platform. If the computational requirements of a video algorithm cannot be met with a single processing unit, multi-core systems often provide an elegant and power-efficient alternative. Unfortunately,efficiently distributing the video algorithm among multiple processing units is a non-trivial task. It requires detailed knowledge about the algorithmic complexity and inter-dependencies between functional blocks. The most severe problem, however, is that there are strong dynamic variations in run time on the basic level of the H.264 decoding process, namely the level of macro blocks. We go into more detail on this dynamic behavior in the following. Roughly spoken, an H.264 stream can be regarded as a sequence of compressed macro blocks. In the decoding process, each macro block is sent through the decoder pipeline one after the other in order to derive the uncompressed video information. When looking at the computation time consumed by each macro block, it is observed that there are large variations.

Posted in Uncategorized | Leave a comment