Monday, November 26, 2012

Linux Shell scripting basics and Simple example to add two numbers

Shell scripting is a file which contains the list of commands for executing. What is Shell? Shell is special program or application provided for the user interaction.
There are different kinds of shells in Unix/Linux, they are
  • Sh: Bourne Shell
  • Csh: C Shell
  • Ksh: Korn Shell
  • Bash: Bourne again Shell.. etc
Some of the advantages of the shell scripting are,
  • Automation of tasks such as backups,log monitoring etc
  • To do repetition of of tasks
  • Save lots of time..
Unix/Linux Shell scripting also containg the functions, control statements,loops like other programming languages C, C++...

Monday, November 12, 2012

Signal handling in Linux using signal() call

signal() function in linux is used to sets of handler for the given signal number, the handler is any of SIG_DFL(default action) or SIG_IGN(ignore signal) or address of user defined function which we called signal handler

syntax:
         sighandler_t signal(int signum, sighandler_t handler);

the second parameter is the address of the signal handler function (function pointer), which has the following syntax

         typedef void (*sighandler_t)(int );

Here the parameter int represents the Signal number.

Here is the simple C program which describes the SIGINT Signal handling in linux

signal.c

#include<stdio.h>
#include<signal.h>

Thursday, November 8, 2012

gethostbyname example in C


gethostbyname() function will return the host details such as hostname, aliase names of the host,type of address, and length of host address of the given hostname.

This function will return the hostent (host entry) structure which contain the all the above details. h_addr_list[0]  field of “hostent” structure will contain struct in_addr equivalent of the host address.


Sysntax

struct hostent *gethostbyname(const char *name);

Here name is any valid hostname  (or) IPV4 address in standard dot notation (or) IPV6  address in colon or dot notation


Here is the simple C Program in Linux that illustrates the gethostbyname() function.

Saturday, November 3, 2012

UDP Client Server C Program

Hii all, in this Post you will learn how to write a simple UDP Socket Program in C in linux to send a message to the server and server will reply you.
Unlike TCP, UDP does not have connection establishment.So there is no connet() system call in client and accept() systemcall in server.

So the System calls in the server are

1.socket()
2.bind()
3.recvfrom()
4.sendto(
and I client the system calls are
1.socket()
2.sendto()
3.recvfrom()

The simple UDP Client-Server Program is as follows


udp_server.c