Thursday 20 August 2015

Linux

Linuxz Pipes |
Linux (pronounced i/ˈlɪnəks/ LIN-əks or, less frequently, /ˈlaɪnəks/ LYN-əks) is a Unix-like and mostly POSIX-compliant computer operating system (OS) assembled under the model of free and open-source software development and distribution.

The UNIX domain sockets (UNIX Pipes) are typically used when communicating between two processes running in the same UNIX machine. UNIX Pipes usually have a very good throughput. They are also more secure than TCP/IP, since Pipes can only be accessed from applications that run on the computer where the server executes.

 

When starting a server using UNIX Pipes, you must reserve a unique listening name (inside that machine) for the server, for instance, 'soliddb'. Because UNIX Pipes handle the UNIX domain sockets as standard file system entries, there is always a corresponding file created for every listened pipe. In solidDB®'s case, the entries are created under the path /tmp Our example listening name 'soliddb' creates the directory/tmp/solunp_SOLIDDB and shared files in that directory. The /tmp/solunp_ is a constant prefix for all created objects while the latter part ('SOLIDDB' in this case) is the listening name in upper case format.


/*Write a program that spawns a child process which inherits two UNIX pipes created by the parent.Based on a command line option, you will then measure the "round-trip" time required to exchange a byte of data using the pipes*/

#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/time.h>
#include<time.h>
int main()
{
int p1[2],p2[2];
struct timeval tv;
char buf[6];
pipe(p1);
pipe(p2);
int i,j,pid;
pid=fork();
if(pid>0)
{
read(p1[0],buf,5);
write(p2[1],buf,5);
}
if(pid==0)
{

gettimeofday(&tv,NULL); //the fuction gettimeofday() is called
i=tv.tv_usec; //record the time before writing
write(p1[1],"HELLO",5);
read(p2[0],buf,5);
gettimeofday(&tv,NULL);
j=tv.tv_usec; //record the time after recieving
printf("\n\nRound tripp time = %d usec\n",j-i); //calculate the diffrence
}
return 0;

}

No comments:

Post a Comment