Showing posts from February, 2014

Simple C programs demonstarting use of mkfifo( ) system call.

SYS CALL NAME mkfifo – make FIFOs (named pipes)SYNOPSIS mkfifo [OPTION]… NAME… DESCRIPTION Create named pipes (FIFOs) with the given NAMEs. Mandatory  arguments  to  long  options are mandatory for short options too. -m, –mode=MODE set file permission bits to MODE, not a=rw – umask -Z, –context=CTX set the SELinux security context of each NAME to CTX –help display this help and exit –version output version information and exit   #include<stdio.h>#include<sys/errno.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include<string.h>void main (){    int fd;    char a[10];    char buff[10];    int i=0;    printf("nnEnter numbersnn");    for(i=0;i<10;i++)    scanf("%c",&a[i]);    char * myfifo = "/home/student/shubham";    /* create the FIFO (named pipe) */    mkfifo(myfifo, 0666);    /* write to the FIFO */    fd = open(myfifo,O_WRONLY);    write(fd,a,sizeof(a));    close(fd);    /* remove the FIFO */  

Simple session based timer for online quize website in PHP

  <?php  session_start();  /* If leave the page or refresh it, then the timer will continue to count down until finished. */  // $minutes and $seconds are added together to get total time.  $minutes = 20; // enter minutes  $seconds = 0; // enter seconds  $time_limit = ($minutes * 60) + $seconds + 1; // converts total time into seconds  if(!isset($_SESSION["start_time"])){$_SESSION["start_time"] =                          mktime(date('G'),date('i'),date('s'),date('m'),date('d'),date('Y')) + $time_limit;}  // Add $time_limit (total time) to start time. And store into session variable.  ?>  <html>  <title>Online Quiz</title>  <head>  <style>  #txt {  border:2px solid red;  font-family:verdana;  font-size:16pt;  font-weight:bold;  background: #FECFC7;  width:80px;  text-align:center;  color:#000000;  }  </style>  </head>  <body >  <script>  var ct = setInterval(&q

Why Is a Block in Hadoop Distributed Filesystem (HDFS) So Large?

HDFS blocks are large compared to disk blocks, and the reason is to minimize the cost of seeks. By making a block large enough, the time to transfer the data from the disk can be made to be significantly larger than the time to seek to the start of the block.Thus the time to transfer a large file made of multiple blocks operates at the disk transfer rate. A quick calculation shows that if the seek time is around 10 ms, and the transfer rate is 100 MB/s, then to make the seek time 1% of the transfer time, we need to make the block size around 100 MB. The default is actually 64 MB, although many HDFS installations use 128 MB blocks. This figure will continue to be revised upward as transfer speeds grow with new generations of disk drives. This argument shouldn’t be taken too far, however. Map tasks in MapReduce normally operate on one block at a time, so if you have too few tasks (fewer than nodes in the cluster), your jobs will run slower than they could otherwise.

Demonstrating use of friend functions in C++

/********************************************************Program Name: Using friend function to find square of a number**********************************************************/#include<iostream.h>#include<conio.h>class squre{private:intx,t;public:void accept();friend void sq(squre a);};void squre::accept(){cout<<"ENTER A NMUBER:-n";cin>>x;}void sq(squre a){a.t=a.x*a.x;cout<<"THE GIVEN NUMBER SQOURE IS:-n";cout<<a.t;}void main(){clrscr();squre s;s.accept();sq(s);getch();}/**************************************************output:-ENTER A NMUBER:-5THE GIVEN NUMBER SQOURE IS:-25***************************************************//********************************************************Program Name: Using friend function to find greater number from two numbers**********************************************************/#include<iostream.h>#include<conio.h>class b;class a{private:int m;public:void accept();friend void max(a,

Handling signals in C program

#include<stdio.h>#include<signal.h>#include<unistd.h>void signal_handler(){int i;for(i=10;i>=1;i--)printf(" %d ",i);printf("nn");alarm(10);}int main(){signal(SIGALRM, signal_handler);alarm(10);while(1);}