EmbLogic's Blog

implemented interprocess communication using pipe

created a communication medium between server and single client. client  sends request to the server to perform an operation.server after performing operations send the result back to the client .this result is again read by the client by using pipe.

Posted in Uncategorized | Leave a comment

implemented interprocess communication without pipe

simply opened file in server side and write the file.this file (file descriptor) is passed as argument through execl to the another program called client which than read the file using sscanf(and then lseek().

Posted in Uncategorized | Leave a comment

Sys_siglist[] and the log file.

RCS file: 2.c,v
Working file: 2.c
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;     selected revisions: 1
description:
how a siglist work.
it contain all the 64 signals.
—————————-
revision 1.1
date: 2014/03/13 05:06:34;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

Common handler using different signal.

RCS file: commonhandler.c,v
Working file: commonhandler.c
head: 1.3
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 3;     selected revisions: 3
description:
making the SIGINT and form the ouch function handler.
—————————-
revision 1.3
date: 2014/03/12 12:32:00;  author: root;  state: Exp;  lines: +3 -2
*** empty log message ***
—————————-
revision 1.2
date: 2014/03/12 12:26:22;  author: root;  state: Exp;  lines: +1 -1
give the signal SIGQUIT against the same function handler i.e ouch
—————————-
revision 1.1
date: 2014/03/12 12:24:58;  author: root;  state: Exp;
Initial revision
=============================================================================

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

Work on the signal() system call.

RCS file: 1.c,v
Working file: 1.c
head: 1.2
branch:
locks: strict
root: 1.2
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;     selected revisions: 2
description:
make the signal handler function against the SIGNINT signal.
—————————-
revision 1.2    locked by: root;
date: 2014/03/12 09:37:32;  author: root;  state: Exp;  lines: +2 -1
on second time when we press ctrl+c then progam terminates because of SIG_DFL
—————————-
revision 1.1
date: 2014/03/12 09:29:22;  author: root;  state: Exp;
Initial revision
=============================================================================

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

Working of alarm using fork,sleep and pause.

RCS file: ./alarm.c,v
Working file: ./alarm.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;    selected revisions: 1
description:
global value for alarm_fired is declared.
setting the child process for 5 sec pause.
meanwhile the parent process will be processing SIGALRM signal.
—————————-
revision 1.1    locked by: root;
date: 2014/03/11 05:46:17;  author: root;  state: Exp;
Initial revision
==================

Posted in Data Structures with C, Project 03: Client Server Communication using Linux and IPC | Leave a comment

Process in Linux

As in our busy life we required multitasking process and with the help of the Linux we can make the multi task processes.

Using the fork() system call(its not a function) we can create a newly process, which is known as child process having Pid set to Zero, and by using execl() system call we can make another process by passing the arguments from the main program and after calling execl() our main program(current process) is to be high jack by our newly process.

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

process is set to default..causing termination of process.

RCS file: ./ignore_sigint.c,v
Working file: ./ignore_sigint.c
head: 1.2
branch:
locks: strict
root: 1.2
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;    selected revisions: 2
description:
ignore the signal using SIG_DFL.
—————————-
revision 1.2    locked by: root;
date: 2014/03/11 05:08:35;  author: root;  state: Exp;  lines: +1 -0
by pressing ctrl+c second time…the signal will be set to default
causing the process to be end.
—————————-
revision 1.1
date: 2014/03/11 05:06:56;  author: root;  state: Exp;
Initial revision

Posted in Data Structures with C, Project 2: Multiple Data Compression and Encryption | Leave a comment

Signal no.2 SIGINT

RCS file: ./sig_int.c,v
Working file: ./sig_int.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;    selected revisions: 1
description:
signal 2 is called….
—————————-
revision 1.1    locked by: root;
date: 2014/03/11 04:58:38;  author: root;  state: Exp;
Initial revision

Posted in Uncategorized | Leave a comment

Implemented Queues-push,pop,display,delete

RCS file: queues.c,v
Working file: queues.c
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2;     selected revisions: 2
description:
this is the initial version ,here i have completed the push function operation by passing the

double void**queues from the main
rear value is incremented and the frount value stays at -1 location
—————————-
revision 2.2
date: 2014/03/10 18:50:40;  author: root;  state: Exp;  lines: +34 -13
enterred display function,pop function and then displaying the result as a output
working fine!!
—————————-
revision 1.1
date: 2014/03/10 09:52:57;  author: root;  state: Exp;
Initial revision
=============================================================================

Posted in Data Structures with C | Leave a comment

swapping variable different method

How to swap two numbers without using a temporary variable?

Given two variables, x and y, swap two variables without using a third variable.

Method 1 (Using Arithmetic Operators)
The idea is to get sum in one of the two given numbers. The numbers can then be swapped using the sum and subtraction from sum.

include <stdio.h>

int main()

{

  int x = 10, y = 5;

 

  // Code to swap 'x' and 'y'

  x = x + y;  // x now becomes 15

  y = x - y;  // y becomes 10

  x = x - y;  // x becomes 5

 

  printf("After Swapping: x = %d, y = %d", x, y);

 

  return 0;

}

 

 

Output:

After Swapping: x = 5, y = 10

Multiplication and division can also be used for swapping.

include <stdio.h>

int main()

{

  int x = 10, y = 5;

 

  // Code to swap 'x' and 'y'

  x = x * y;  // x now becomes 50

  y = x / y;  // y becomes 10

  x = x / y;  // x becomes 5

 

  printf("After Swapping: x = %d, y = %d", x, y);

 

  return 0;

}

 

Output:

After Swapping: x = 5, y = 10

Method 2 (Using Bitwise XOR)
The bitwise XOR operator can be used to swap two variables. The XOR of two numbers x and y returns a number which has all the bits as 1 wherever bits of x and y differ. For example XOR of 10 (In Binary 1010) and 5 (In Binary 0101) is 1111 and XOR of 7 (0111) and 5 (0101) is (0010).

#include <stdio.h>

int main()

{

  int x = 10, y = 5;

 

  // Code to swap 'x' (1010) and 'y' (0101)

  x = x ^ y;  // x now becomes 15 (1111)

  y = x ^ y;  // y becomes 10 (1010)

  x = x ^ y;  // x becomes 5 (0101)

 

  printf("After Swapping: x = %d, y = %d", x, y);

 

  return 0;

}

Output:

After Swapping: x = 5, y = 10

Problems with above methods
1) The multiplication and division based approach doesn’ work if one of the numbers is 0 as the product becomes 0 irrespective of the other number.

2) Both Arithmetic solutions may cause arithmetic overflow. If x and y are too large, addition and multiplication may go out of integer range.

3) When we use pointers to variable and make a function swap, all of the above methods fail when both pointers point to the same variable. Let’s take a look what will happen in this case if both are pointing to the same variable.

// Bitwise XOR based method
x = x ^ x; // x becomes 0
x = x ^ x; // x remains 0
x = x ^ x; // x remains 0

// Arithmetic based method
x = x + x; // x becomes 2x
x = x – x; // x becomes x

x = x – x; // x becomes 0

Let us see the following program.

#include <stdio.h>

void swap(int *xp, int *yp)

{

    *xp = *xp ^ *yp;

    *yp = *xp ^ *yp;

    *xp = *xp ^ *yp;

}

 

int main()

{

  int x = 10;

  swap(&x, &x);

  printf("After swap(&x, &x): x = %d", x);

  return 0;

}

Output:

After swap(&x, &x): x = 0

Swapping a variable with itself may needed in many standard algorithms. For example see this implementation of QuickSort where we may swap a variable with itself. The above problem can be avoided by putting a condition before the swapping.

#include <stdio.h>

void swap(int *xp, int *yp)

{

    if (xp == yp) // Check if the two addresses are same

      return;

    *xp = *xp + *yp;

    *yp = *xp - *yp;

    *xp = *xp - *yp;

}

int main()

{

  int x = 10;

  swap(&x, &x);

  printf("After swap(&x, &x): x = %d", x);

  return 0;

Output:

After swap(&x, &x): x = 10
Posted in Uncategorized | Leave a comment

Creating two clients from same server and making communication possible.

RCS file: ser.c,v
Working file: ser.c
head: 1.9
branch:
locks: strict
akshat: 1.9
access list:
symbolic names:
keyword substitution: kv
total revisions: 9;    selected revisions: 9
description:
IPC- INTERPROCESS COMMUNICATION, communication btw two processes invoking a fork call and then hijacking that child process for one way communication.
—————————-
revision 1.9    locked by: akshat;
date: 2014/03/09 05:44:19;  author: akshat;  state: Exp;  lines: +18 -3
creation of another pipe on same server.
its working.
—————————-
revision 1.8
date: 2014/03/09 04:15:57;  author: akshat;  state: Exp;  lines: +12 -2
Creating another pipe for passing requests of client 1.
client 2 will process these requests.
server will then output the result to client 1.
—————————-
revision 1.7
date: 2014/03/07 21:51:57;  author: akshat;  state: Exp;  lines: +11 -7
read and write fd are sent simultaneously.
—————————-
revision 1.6
date: 2014/03/07 17:01:18;  author: akshat;  state: Exp;  lines: +1 -1
trying to pass both the arguments.
—————————-
revision 1.5
date: 2014/03/07 16:47:34;  author: akshat;  state: Exp;  lines: +6 -6
using wait statement for parent, process not hanged.
pipe created successfully.
—————————-
revision 1.4
date: 2014/03/07 16:43:15;  author: akshat;  state: Exp;  lines: +11 -7
its working, but process hangs.
checking for it.
—————————-
revision 1.3
date: 2014/03/07 16:31:13;  author: akshat;  state: Exp;  lines: +4 -2
lets see if its working
—————————-
revision 1.2
date: 2014/03/07 16:28:02;  author: akshat;  state: Exp;  lines: +9 -3
pipe is formed.
client is formed by hijacking the child.
—————————-
revision 1.1
date: 2014/03/07 15:21:25;  author: akshat;  state: Exp;
Initial revision
=============================================================================

Posted in Uncategorized | Leave a comment

how to give command line arguments to a self defined command created using shell scripting?

 

this script uses two arguments given while using the command (script name) which it uses to replace $1 (first argument) $2 (second argument).

Posted in Shell Scripts | Leave a comment

Where Are the Linux Kernel Files?

The kernel file, in Ubuntu, is stored in your /boot folder and is called vmlinuz-version. The name vmlinuz comes from the unix world where they used to call their kernels simply “unix” back in the 60?s so Linux started calling their kernel “linux” when it was first developed in the 90?s.

When virtual memory was developed for easier multitasking abilities, “vm” was put at the front of the file to show that the kernel supports virtual memory. For a while the Linux kernel was called vmlinux, but the kernel grew too large to fit in the available boot memory so the kernel image was compressed and the ending x was changed to a z to show it was compressed with zlib compression. This same compression isn’t always used, often replaced with LZMA or BZIP2, and some kernels are simply called zImage.

The version numbering will be in the format A.B.C.D where A.B will probably be 2.6, C will be your version, and D indicates your patches or fixes.

In the /boot folder there will also be other very important files called initrd.img-version, system.map-version, and config-version. The initrd file is used as a small RAM disk that extracts and executes the actual kernel file. The system.map file is used for memory management before the kernel fully loads, and the config file tells the kernel what options and modules to load into the kernel image when the it is being compiled.

Posted in Project 1: A Linux Administration based Project | Leave a comment

Module code to show how to implement a semaphore(a type of locking technique) in scull to synchronize same operations issued by multiple applications.

Semaphore in Scull

Scenario :Writer application must execute before the reader application.

There are two applications which have to perform several operations on the node

1. Application 1: Application 1 is a multithreaded application in which open() , write() and close() functions are called in multiple threads.And because this has to be done in this specific order ,synchronization is achieved with the help of thread semaphores.

2.Application 2:Application 2 is also a multithreaded application in which open() , read() and close() functions are also called in multiple threads and synchronization between them is achieved by thread semaphores.

As these two multi-threaded applications issues open() call.There is a need to implement the  semaphores at the kernel level also .
RCS file: openf.c,v
Working file: openf.c
head: 1.15
branch:
locks: strict
root: 1.15
access list:
symbolic names:
keyword substitution: kv
total revisions: 15;    selected revisions: 15
description:
The functionality of chardev_open() is implemented here inside this file.Whenever the application calls the open function,this is always the first operation performed on the device file.
—————————-
revision 1.15    locked by: root;
date: 2014/03/07 19:18:40;  author: root;  state: Exp;  lines: +1 -1
If the application issues open() system call in O_RDONLY mode , then it decrements the value of the semaphore sem which is initialized with 0 and blocks itself untill the writer executes up() on the same semaphore.

Status : chardev_open() , chardev_write() and chardev_read() are perfectly synchronized.
—————————-
revision 1.14
date: 2014/03/07 19:12:31;  author: root;  state: Exp;  lines: +12 -15
Logical bug fixed.
Issue:&& is used instead of & while bitwise ANDing O_ACCMODE with filep->f_flags.

Also added a check for O_RDONLY mode.
Status : Open is working correctly.
—————————-
revision 1.13
date: 2014/03/01 20:24:26;  author: root;  state: Exp;  lines: +12 -4
Compilation successfull and chardev_trim() function is working fine.
Issue:Trying the free the memory that is not allocated in case of quantum.
Logical error fixed.
—————————-
revision 1.12
date: 2014/03/01 19:41:54;  author: root;  state: Exp;  lines: +4 -0
kernel crash taking place inside chardev_trim() function.
Issue inside chardev_trim() function.
Debugging……………………………
—————————-
revision 1.11
date: 2014/03/01 19:38:30;  author: root;  state: Exp;  lines: +1 -1
Syntax error fixed.
Issue:Missing semicolon.
—————————-
revision 1.10
date: 2014/03/01 19:37:04;  author: root;  state: Exp;  lines: +12 -4
One bug fixed.
Issue:qset_size variable is included using extern.
Debugging…..
—————————-
revision 1.9
date: 2014/03/01 13:09:52;  author: root;  state: Exp;  lines: +49 -3
Implementing chardev_trim() function.Inside this function,firstly certain checks are made to make sure that Sculldec , scullqset , qset and quantums exist or not.
If any of such things do not exist an error message is reported.Now performing trimming………..
—————————-
revision 1.8
date: 2014/03/01 12:08:22;  author: root;  state: Exp;  lines: +23 -1
Two printk statements are added inside the chardev_trim() function to mark its beginning and end.
Checking……….
—————————-
revision 1.7
date: 2014/03/01 11:57:45;  author: root;  state: Exp;  lines: +5 -0
O_ACCMODE is a macro that stands for a mask that can be bitwise-ANDed with the file status flag value to produce a value representing the file access mode.The mode will be O_WRONLY,O_RDONLY or O_RDWR.
The O_ACCMODE macro is used inside the chardev_open() function to find out the file access mode.
—————————-
revision 1.6
date: 2014/03/01 08:45:54;  author: root;  state: Exp;  lines: +5 -1
Printing the address stored inside the lsculldev to check whether it matches with the filep->private data address printed inside the chardev_release() function.
—————————-
revision 1.5
date: 2014/03/01 08:33:40;  author: root;  state: Exp;  lines: +1 -0
Once the Sculldev structure is found by the container_of() macro,a pointer to the scull is stored in the private_data field of the file structure for easier access    .
—————————-
revision 1.4
date: 2014/03/01 08:25:52;  author: root;  state: Exp;  lines: +11 -4
A local variable of type struct Sculldev is declared.
Used container_of() inside the open function.This macro has 3 arguments:
1.A pointer to a field named container_field.
2.This container field within a structure of type container_type,and
3.ccontainer field.
On success it returns a pointer to the containing structure.
—————————-
revision 1.3
date: 2014/02/28 18:51:08;  author: root;  state: Exp;  lines: +2 -0
Included the prototype of chardev_open() using extern.
—————————-
revision 1.2
date: 2014/02/28 18:42:56;  author: root;  state: Exp;  lines: +15 -0
Two printk statements are used to test that whether the open function is actually begin and ended.\
—————————-
revision 1.1
date: 2014/02/28 18:33:28;  author: root;  state: Exp;
Initial revision
=============================================================================

/home/Deepak/Desktop/wror

 

Posted in Character Driver, Device Drivers | Leave a comment