Since there are 10485760 bytes in 10 megabytes and i did 1,000000000 for the gigabyte and when you divide them it will take .01048576 seconds for it to transfer a 10 mb file with a 1gb speed.
.001274 seconds with the length of 36000 and the speed of light at 299792458 m/s. Since the latency is both of them added up.001274+.01048576 = .01175976
3b.
With a 10bps rate and not a gigabyte rate the change is large with a 10 megabyte file still which is 10485760 bytes it will take 1048576 seconds which is around 291 hours. with a 2m link and the speed still the same it becomes .000000006712819. The latency becomes 1048576 seconds.
4.
Piping is a process where the output of one process is made the input of another. First you must create a pipe and then open the pipe like this FILE *popen(char *command, char *type) This is how you create a pipe int pipe(int fd[2]). Since shared memory is basically data transfer and transferring data is easier if the output and the input go hand in hand. Therefore pipes are important for shared memory.
Credits to http://www.cs.cf.ac.uk/Dave/C/node23.html
5.
The functions fread/fwrite are used for reading/writing data from/to the file opened by fopen function. These functions accept three arguments. The first argument is a pointer to buffer used for reading/writing the data. The data read/written is in the form of ‘nmemb’ elements each ‘size’ bytes long. In case of success, fread/fwrite return the number of bytes actually read/written from/to the stream opened by fopen function. In case of failure, a lesser number of byes (then requested to read/write) is returned.
ex.
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
#include<stdio.h> #include<string.h> #define SIZE 1 #define NUMELEM 5 int main(void) { FILE* fd = NULL; char buff[100]; memset(buff,0,sizeof(buff)); fd = fopen("test.txt","rw+"); if(NULL == fd) { printf("\n fopen() Error!!!\n"); return 1; } printf("\n File opened successfully through fopen()\n"); if(SIZE*NUMELEM != fread(buff,SIZE,NUMELEM,fd)) { printf("\n fread() failed\n"); return 1; } printf("\n Some bytes successfully read through fread()\n"); printf("\n The bytes read are [%s]\n",buff); if(0 != fseek(fd,11,SEEK_CUR)) { printf("\n fseek() failed\n"); return 1; } printf("\n fseek() successful\n"); if(SIZE*NUMELEM != fwrite(buff,SIZE,strlen(buff),fd)) { printf("\n fwrite() failed\n"); return 1; } printf("\n fwrite() successful, data written to text file\n"); fclose(fd); printf("\n File stream closed through fclose()\n"); return 0; }Credits to http://www.thegeekstuff.com/2012/07/c-file-handling/
good but needed the function desc to be more clean and standard
ReplyDelete