Question 3
Consider a transmission link that 36000m long and uses 1 Gbps transmission speed. How long it will take to transmit a 10MB file along this link? Repeat this question for a 2m long link with 10bps transmission rate. Assume that the propagation speed is equal to the speed of light.
Latency - delays to send a message over a link
Transmission delay: time to put M-bit message "on the wire"
M / R seconds
Propagation delay: time for bits to propagate across the wire
Length / 2/3c = D seconds
c = 299792458 (speed of light)
Assume that the propagation speed is equal to the speed of light.
Transmission delay:
M / R = 10MB / 1Gps
= ( 10 * 1048576 ) 8 / 1000000000
= 0.83886080 seconds
= 83.886 ms
Propagation delay:
D = 36000 / c
= 36000 / 299792458
= 0.0001200830743 seconds
= 0.120083074 ms
L = ( M / R ) + D
= 83.886 + 0.120083074
= 84. 00608307 ms
-----------------------------------------------
Transmission delay:
M / R = 10MB / 10bps
= ( 10 * 1048576 ) 8 / 10
= 8388608 seconds
= 8.389x10^9 ms
Propagation delay:
D = 2 / c
= 2 / 299792458
= 0.0000000066728 seconds
= 0.0000066728 ms or 6.6728x10^-6
L = ( M / R ) + D
= 8.389x10^9 + 6.6728x10^-6
= 8.389x10^9 ms
Pipe uses an access point which is a file in the file system. A method for writing and reading between two given inter-connected functions or two set of functions called message pipe. Writing and reading to a pipe is likely using a C command which are fwrite wit a file name that writes into a named file, fread with a file name that reads into a named file. The fwrite function can write to a pipe at the back pointer address using *pback. The fread function can read from a pipe at the front pointer address using *pfront. The message pipe at the pipe function memory buffer for writing and reading as FIFO. The limitation in a pipe may have a variable number bytes per message among initial and final pointers.
Functions implementing Pipe:
- using pipefunccreate( ) is a function to initialize a pipe function.
- using open ( )is for opening function to implement it use from the starting of its allocated buffer. It uses with option and condition defined at the time of opening
- using open ( )is for opening function to implement it use from the starting of its allocated buffer. It uses with option and condition defined at the time of opening
- using connect( ) is for connecting a thread or function filling in bytes into the pipe to the thread or function eliminating bytes from the pipe
- using write( ) is a function for writing or inserting into the pipe from the bottom of the empty memory space of its allocated buffer
- using read( ) is a function for reading or deleting from the pipe from the bottom of the unread memory spaces in the buffer loaded after writing into the pipe
-using close( ) is for closing the function to set up its purpose from the beginning of its buffer allotted only after opening it again
- using write( ) is a function for writing or inserting into the pipe from the bottom of the empty memory space of its allocated buffer
- using read( ) is a function for reading or deleting from the pipe from the bottom of the unread memory spaces in the buffer loaded after writing into the pipe
-using close( ) is for closing the function to set up its purpose from the beginning of its buffer allotted only after opening it again
Shared memory is an efficient means of passing data between programs. one program will create a memory portion which other processes can access once it is permitted. One process writes into the memory and other read it. Shared memory differs from pipes since multiple process can read and write however user need to provide mutual exclusion for read and write. pipes do almost the same except that only one process can read.
shared memory gives more control over buffering and resources. its the person who decides how much memory to allocate and how to use it. in other words, shared memory is more manual than pipes.
basic functions for shared memory include:
shmget() way to identify a thread
shmat() a process gets address-ability to the shared memory
shmdt() a process detaches shared memory
shmctl() a thread removes a shared memory ID
(collaborated with Gerson Rivera and Kristen Diaz)
Question 5
fwrite and fread functions use for reading/writing data from/to the file opened by the function fopen. Both fread and fwrite functions obtain three cases. The first case is when a pointer to buffer that used for reading writing the data.
#include<stdio.h>
#include<string.h>
#define SIZE 1
#define num_of_elem 5
int main( )
{
FILE* file = NULL;
char buffer [100];
memset ( buffer, 0, sizeof (buffer) );
file = fopen ( "test.txt", "rw+");
if ( NULL == file )
{
printf ( "\n Error obtain on fopen().\n" );
return 1;
}
printf ( "\n Successfully file opened.\n ");
if ( SIZE* num_of_elem != fread ( buffer, SIZE, num_of_elem, file ) )
{
printf ( "\n Failed to read file\n" );
return 1;
}
printf ( "\n Bytes successfully read.\n" );
printf ("\n Bytes read are [%s]\n",buffer);
if ( SIZE* num_of_elem != fwrite ( buffer, SIZE, strlen ( buffer ), file) )
{
printf ( "\n Failed on fwrite().\n" );
return 1;
}
printf ( "\n Successfully writes to text file\n" );
fclose ( file );
printf ( "\n File closed.\n" );
return 0;
}
Source: thegeekstuff.com
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.