3) (b-bits, B-bytes)
Transmission Delay: (M/R)
M/R= 10mb(83886080 b)/1gbps(1000000000 b)
M/R= 0.083886 s
Propagation delay: (D)
speed of light
(C)= 299792458 m/s
2/3(c)= 199861639 m/s
length/((⅔)C): 36000m/199861639m/s = 0.000180126 s
Latency= (M/R)+D
0.083886 s + 0.000180126 s= 0.08406613 s
-----------------------------------------------------------------
Transmission Delay: (M/R)
M/R= 10mb(83886080 b)/10bps(10 b)
M/R= 838860 s
Propagation delay: (D)
speed of light(C)= 299792458 m/s
2/3(c)= 199861639 m/s
2m/199861639 m/s= 0.000000001000692 s
Latency= (M/R)+D
0.000000001000692 s + 838860 s = 838860.000000001 s
4)
Pipe is one type of interprocess communication that connects one or more clients to the server, through one or more processes. This enables communication or the transfer of data between server and client.
Pipe Functions:
- pipe() - creates a pipe, a unidirectional data channel that can be used for interprocess communication
- open() - opens a function and establishes the connection between a file and a file descriptor
- connect() - connects a function by trying to connect to a socket.
- write() - attempts to write nbyte bytes from the buffer pointed to by buf to the file associated with the open file descriptor
- read() - attempts to read up to count bytes from file descriptor fd into the buffer starting at buf.
- close() - closes a file descriptor, so that it no longer refers to any file and may be reused.
Shared memory is all about data transfer between programs. One side of the program will basically be about creating memory, and the other is all about reading it. This varies as compared to pipes, because pipes don’t have all the functionality that shared memory has. Shared memory gives the user more control and freedom over what is allocated and when.
Shared memory functions:
shmget() - returns the identifier of the shared memory segment associated with the value of the argument key.
shmat() - attaches the shared memory segment identified by shmid to the address space of the calling process.
shmdt() - attaches the shared memory segment identified by shmid to the address space of the calling process
shmctl() - performs the control operation specified by cmd on the shared memory segment whose identifier is given in shmid.
5)
/*
* fwrite example code
*
*/
* fwrite example code
*
*/
- The fwrite() function writes, from the array buffer, count objects of size size to stream. The return value is the number of objects that were written.
- To read the file, use fread.
#include <stdio.h> /* including standard library */
struct CD_COLLECTION {
char album_name[42];
int year;
char artist[42];
};
int main (void)
{
FILE *stream = fopen ("collection.bin","wb");
struct CD_COLLECTION collection[5];
unsigned short i = 0;
for (i=0; i < 5 ; i++) {
sprintf(collection[i].album_name, "Interpret %i", i);
collection[i].year=2012;
sprintf(collection[i].artist,"Mr Unrockable %i", i);
}
fwrite (collection, sizeof(struct CD_COLLECTION), 5, stream);
fclose (stream);
return 0;
}
/*
* fread example code
*
*/
* fread example code
*
*/
- fread reads num number of objects from a stream (where each object is size bytes) and places them into the array pointed to by buffer. The return value of the function is the number of read data
- To generate the binary file, you have to use fwrite.
#include <stdio.h> /* including standard library */
struct CD_COLLECTION {
char album_name[42];
int year;
char artist[42];
};
int main (void)
{
FILE *stream = fopen ("collection.bin","rb");
struct CD_COLLECTION collection[5];
unsigned short i = 0;
fread (collection, sizeof(struct CD_COLLECTION), 5, stream);
for (i=0; i<5 ; i++) {
printf("Album Name: %s\nYear %i\nArtist: %s\n\n",collection[i].album_name, collection[i].year, collection[i].artist);
}
fclose (stream);
return 0;
}
Thanks for the nicely formatted blog
ReplyDelete