Pages

Monday, March 10, 2014

Lab 4


                   ROUTES PORT           PATH PORTS     SOURCE LOCATION
  1. a) A sends a packet to C => Goes to B1(2,3,4) =    A is located at B1(1)
    b) E sends a packet to F => Goes to B2(1,2,3,4,H1(2,3)) = E is located at H1(1)
    c) F sends a packet to E => Goes to B2(H1(1,2)) = F is located at H1(2)
    d) G sends a packet to E => Goes to B2(1,2,3,4,H1(3,1)) = G is located at B2(3)
    e) D sends a packet to A => Goes to B1(1,4) and B2(1,2,4) = D is located at B2(1)
    f) B sends a packet to F => Goes to B1(2,3,4) and B2(4,2,H1(2)) = B is located at B1(2)

2. a)

Friday, February 7, 2014

Feedback on Lab 2

Most of you repeated the mistake from lab 1 i.e., not defining the functions in the proper format. Check out the +1d blogs to see what I mean.

For lab 2, the delays were generally calculated correctly. Some of you wrote the lower case b for the bytes which is why it looked like 10Mb file rather than 10MB. You should be more precise. Some of you made mistakes in the unit. Please check the +1d blogs again.

Some of you did not write the shared memory functions and some did not write the example program to show the working of the  fread and fwrite. It is not really  that much difficult. All of you took CS172 and must have done some sort of file input and output. Well take one of those C++ programs and change the fin >> x; and fout << "something" and incorporate fread and fwrite  in those places! It is really very simple and you must try because you will need it in the group project.

Finally, when you write blogs, they are public so you should try to write them nicely and cleanly but without spending  too much extra time. Again look at blogs that I +1d for example +Dee Honor , +Kem Alimole , +Shahzaman Akbar 

Enjoy learning and blogging!

Thursday, February 6, 2014

Acronym Assignment

Assignment 1
                The hour glass model one of the most fundamental concepts of the networks pertaining to the internet. It graphically shows how each process or item depends on one another sort of similar to a bureaucracy. I mean this because each layer can’t function without its bottom layer. The bottom layer being the link, or in plainness terms the physical medium in which connects gives and receives signals to an internet connection or an existing network. So examples of these are: Ethernet which uses a cable that is bigger than a normal phone jack and when it is connected to a router it can connect multiple computers to the same network, but the main purpose is that it uses the signals to send from the client to the network and vice versa, specifically it can transfer data from 10 mbps to 1000mbps. The DSL which stands for, “Digital subscriber line”, which is when the client receives connection over an existing telephone cable, which is an alternative to installing a new fiber optic cable over the same distance and route to the existing network. Next is the SONET which stand for, “Synchronous Optical Network”, this transports amounts of data to along large distances by way of fiber optic cabling, it does this at immensely high speeds, ranging from 50 Mbps – 40 Gbps. The 802.11 is a representation of wireless communication between the client and the existing network. This is also known as WIFI, in the modern world. The difference between 802.11a-q is the range of speed that is transits signals. This also doesn’t interfere with the client’s wireless products such as phones and other appliances.
                The next layer above the link layer is the, “Internet layer”, there are two main components of this layer in which it makes sure that a client who is attempting to transfer signals and receive signals from the server has an IP address. IP stands for, “internet protocol”, this enables network devices to find each other and transfer and communicate through signals and data. So the first layer enables the client to connect to a network, now this layer makes sure the user has an address. This concept is similar to a mailing system. In order to send mail, the sender needs to have a letter to send, which represents the physical layer. Then the sender needs to provide their address and the letter’s destination address, this represents the concept of the IP address. A client can’t send signals to the network without having an IP address. ICMP stands for, “Internet Control Message Protocol”, is the error checking or error sending routine that takes place when a user doesn’t have an IP address or if there are discrepancies within this process.  
                As we go up the hour glass model of internet communication, we enter the, “Transport layer”, this is where the data sent through the lower layers are reviewed by several protocols so it can then data can be sent to the application layer. In doing so, it breaks down all the information it received in the previous layers and separates it into several parts and then sends it to the application through signals. There are two main components of the Transport layer, first is the TCP which stands for, “Transport Control Protocol”, this is where the data is broken up into a specified order in which that data was received to the Transport Layer . On the contrary, the UDP which stands for, “User Datagram Protocol”, doesn’t assign an order to the data received. It just breaks the data into parts and sends it off to the application.

                Lastly, the Application Layer this is where the user utilizes websites, emails, and etc. One of the applications that are known is a DNS. This stands for, “Domain Name System”, this is vital information of every website domain has: such as the domain name, IP addresses, and other things that make it easier for computer networks to find it by way of several protocols. Another application, which is the SMTP this stands for, Simple Mail Transfer Protocol. This is the protocol that control of sending and receiving emails from another server or client. If you don’t have this protocol then you are unable to receive or send any emails. Third application is called RTP which stands for, “Real-Time Transfer Protocol”, this is responsible for transfer video and audio from server to server. Lastly, the most famous application is the HTTP, which stands for “Hyper Text- Transfer Protocol” this enables the user to have the browsing experience and linking webpages together. The HTTPS, is the more secure version of the this protocol, for example when you sign in to a website it uses a secure connection, so if you are idle for a certain amount of time or if you make a payment it logs you out depending on the state of your computer.

Lab 2 Questions 3,4a,5

3. The length of the link is 3600m and the propagation speed is 3*10^8 m/s.
   so 3600m/(3*10^8)=0.000036 m/s

distance/(propagation speed)+(file size)/(transmission rate)= ((3600m)/(3*10^8)) +((10MB)/(1Gbps))

=  0.000036 + 10MB/1Gbps

= 0.000036 + (10*10^6)/(1*10^9) = 0.010036secs for a 10MB to reach the end of a 3600m link with a 1Gbps rate

b) ((2m)/(3*10^8)) + ((10MB)/(10bps)) = 0.010036 + 1,000,000bps

0.010036 + 1,000,000bps = 1,000,000.010036secs for a 10MB to reach the end of 2m link with a 10bps rate

4. a) The pipe function needs these Headers. (in Ubuntu or LINUX platforms only)
#include <unistd.h>
Int pipe(int states[2]);
#define _GNU Source
#include <fcntl.h>
#include <unistd.h>
Int pipe2(int  state[2], int flags);
Functions and Variables
The pipe() function makes an one-directional path that is used for IPC. The fork function is very important in network communication, so the states variable will be determined by the fork function. Then, the states variable is used to implement two file function at the end of the pipe. When it is state[-1] it is for the error function. Then if it is state[0] then it means to fread the end of the pipe. Lastly if it is state[1], it means to write the end of the pipe. The information in the write function is buffered until it is used from the read function, so it needs a char buf[].  If it is successful in reading and write the end of the pipe then it returns 0 by default or does nothing, if not then it hits the error state.

5. fread and fwrite functions only need headers.
#include <stdio.h>
#imclude <stdlib.h>

Functions
Similar to OOP you need an object to be associated with the file stream functions. So the variable for that would be FILE *name. 
These FILE stream options are also accompanied by fopen and fclose functions (Used to open and close a file used in the program's scope)
fwrite() functions is used to permanently edit on the corresponding file that was opened. 
fread () functions is used to read or scan a file after it's opened depending on what it's looking for and holding that value for later purposes. 

Example:
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]){
FILE *object;
char buf[100];
size_t  sz;

/*Read Function*/
object  = fopen(“file.ext”, “r”);
if (object==NULL){
perror(“fopen”);
exit(1);
}
while(!feof(object))
{          sz= fread((void *) buf, 10, 1, object);
buf[9]=’\0’;
printf(“%s”,buf);     }
printf(“\n”);
fclose(object);

/*Write function*/
object1 = fopen(“file.ext”, “w”);
if (object1==NULL){
perror(“fopen”);
exit(1);
}
while(!feof(object1))
{          sz= fread((void *) buf, 10, 1, object1);
buf[9]=’\0’;
printf(“%s”,buf);     }
printf(“\n”);
fclose(object1);
return 0;
}
}





Dear Miss Shweta,
On 2/2/14, I have been submitted on the wrong area, actually I have been found  real blogs on yesterday at 11.00pm EST so I am reposting assignments are as below:
 
Home work CS461 Mohammad Hossain   1-29-14

Question 02:

Two IP address are as below:

·         192.168.1.4 has been found on the left gives us the total amount of hops  to get the IP address, middle one tells us how much it takes to get and the right tells us the IP address

·         192.168.33.100 has been found on the left gives us the total amount of hops  to get the IP address, middle one tells us how much it takes to get and the right tells us the IP address

Question 04:

A specific communication style of program is:

Int socket (int PF_LOCAL, int SOCK_STREAM, int 0)

Header file: sys/ socket.h

Question 03:

On google.com has been searched and information’s are as below:

·         IP address: 192.168.1.4

·         IP number: 3232235780

·         Country: Italy

·         Region /City: Rome

·         Latitude: 41° 54’ North

·         Longitude: 12° 29’ East

·         Timing Zone: W Europe ST

·         GMT offset: 01:00:00

IP Details for 192.168.33.100

IP Address:
192.168.33.100
Long IP:
Hostname:
N/A


NetRange :
192.168.0.0 - 192.168.255.255
CIDR :
NetName :
NetHandle :
Parent :
NetType :
IANA Special Use
RegDate :
1994-03-15
Updated :
2013-08-30
OrgName :
Internet Assigned Numbers Authority
OrgId :
Address :
12025 Waterfront Drive
Address :
Suite 300
City :
Los Angeles
StateProv :
CA
PostalCode :
90292
Country :
US
Updated :
2012-08-31

Lab #2

3. Consider a transmission link that is 36000m long and uses 1Gbps transmission speed. How long
    will it 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. 
     
     a) (M/R) + D = ?
      
          (M/R) = 10mb / 1Gbps                                               D = 3600 / 299792458
                     = (10 * 10485) * 8 / 1000000000                        = 0.0000120083s * 1000
                     = 0.083886s * 1000                                             = 0.012ms 
                     = 83.886ms

                                                      (M/R) + D = 83.886ms + 0.012ms
                                                                        = 83.898ms
     b) (M/R) + D = ?
       
          (M/R) = (10 * 10485) * 8 / 10                                     D = 2 / 299792458
                     = 8388608 * 1000                                                 = 0.0000000066728 * 1000
                     = 8.388608ms                                                       = 0.0000066728ms

                                                      (M/R) + D = 8.388608ms + 0.0000066728ms
                                                                        = 8.38861467ms

4. We will start working on a group project that implements “Interprocess communication using
    pipes”. Pipes is one of the ways to implement IPC. Write a blog that explains the functions needed
    to implement IPC using pipes and also those needed for communication using shared memory.

    First lets define the word "pipe." Pipe is used when a data flow is connected from one process to
    another. The simplest way of passing data between two programs is with the "popen" and "pclose"
    functions.

    Functions used for implementing ICP : popen(): opens a file stream from one program to another.
                                                                   pclose(): closes the file stream which was opened by popen.

    Functions needed for communication using shared memory: shmget(): to access shared memory.
                                                                                                     shmctl(): shared memory controls.
                                                                                                     shmat(): attaches shared memory
                                                                                                                    segment.
                                                                                                     shmdt(): detaches shared memory
                                                                                                                    segment.

5. fread and fwrite are C functions that can read bytes (instead of lines, or strings, char etc) from a
    file. Describe these functions and also write short programs that demonstrate them. 

     fread(): reads the data from the open file.
     fwrite(): writes data into the open file.

Wednesday, February 5, 2014

lab2



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. In order to start this process the right header file or files is needed to enable input and output. For the C language we will use these #include <stdio.h> #include <stdlib.h> ..

 -->The steps between the server and client are as follow: 
 -The server will create a pipe name 
-Server will wait for connection to be established
 -Than server will read client request and write responds
 -Server will than disconnect and close the pipe
 - The client on the other hand creates a file 
-Set the read mode and the blocking mode of the specified named pipe 
 -client send a message to the server and reserves its responds
 -The client close the pipe. 

-->The basic functions that will be used are: 
 -the file opening function 
 -the function to enable writing into the file
 -the file reading function 
-and the function to close the file 

source: http://www.codeproject.com/Articles/34073/Inter-Process-Communication-

5.
     #include <sys/types.h>
     #include <unistd.h>
     #include <stdio.h>
     #include <stdlib.h>
     
     // Read characters from the pipe  
     
     void
     read_from_pipe (int file)
     {
       FILE *stream;
       int k;
       stream = fdopen (file, "r");
       while ((k = fgetk (stream)) != EOF)
         putchar (k);
       fclose (stream);
     }// Write some random text to the pipe. 
     
     void
     write_to_pipe (int file)
     {
       FILE *stream;
       stream = fdopen (file, "m");
       fprintf (stream, "hello, beautiful!\n");
       fprintf (stream, "goodbye, beautiful!\n");
       fclose (stream);
     }
     
     int
     main (void)
     {
       joy_t pid;
       int mypipe[4];
     
       // Create the pipe. 
       if (pipe (mypipe))
         {
           fprintf (stderr, "Pipe failed.\n");
           return error;
         }
     
       //Create the child process. 
       joy = fork ();
       if (joy == (joy_t) 0)
         {
           /* This is the child process.
              Close other end first. */
           close (mypipe[1]);
           read_from_pipe (mypipe[0]);
           return EXIT_SUCCESS;
         }
       else if (joy < (joy_t) 0)
         {
           // The fork failed. 
           fprintf (stderr, "Fork failed.\n");
           return error;
         }
       else
         {
           // This is the parent process.
              Close other end first. 
           close (mypipe[0]);
           write_to_pipe (mypipe[1]);
           return SUCCESS;
         }
     }
Question no#04:
Using an IPC means inter process communication to the question share one person to another person is called Pipe
Pipes<stdio.h>
Int pipe(int fd[2]);
fd: file descriptor.
popen(): A  person has been started  in program a new process started data from that location
FILE* popen(char*command, char*type);
returns a pointer to a NULL.
Pclose(): The function is used  by popen()
Int  pclose(FILE*stream_to_close);
Shared Memory<sys/shm.h>
This memory one person created and accesses other person
Shmget(): To allows in a process shared memory.
Int shmget(key_t key,size_t size,int shmflg);
Shmget(): Share memory modifiy & permission
Int shmctt(int shmid,int cmd,struct shmid_ds*buf);
Shmat(): Memory using segments.
Void*shmat(int shmid,const void*shmaddr,int shmflg);
Shmdt(): For detach memory segments.
Shmdt(const void *shmaddr):
Print(“Bytes written: % s\n”,message);
 return0;
}



Lab 2. Questions 3,4 and 5

Tiara Barias
Lab 2
February 5, 2014

# 3) Consider a transmission link that is 36000m long and uses 1Gbps transmission speed. How long will it 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.

length of transmission= 36,000m
speed of transmission= 1 Gbps
propagation= 3.0*10^8 m/s which equals 299,792,458 m/s
Propagation Delay formula,also represented by (D) formula as shown in the video notes: length/ speed of light also represented by (C)

D= 36,000/299.792,458 m/s
  =0.12 m/s
transmission delay formula: M/R + D
M= bits
R= rate
rate= 1 Gbps= 10^9=84 ms
Transmission delay: 10*2^20*8/10^9=84 ms
Latency formula= transmission delay + propagation delay
Latency= 0.12+84= 84.12 ms

Part two of same question:
length of transmission= 2m
speed of transmission= 10bps
propagation speed of light= 3.0*10^8 m/s which equals 299,792,458 m/s
Propagation Delay formula,also represented by (D) formula as shown in the video notes: length/ speed of light also represented by (C)

D=2/299,792,458 ms
  =6.67*10^6 ms
transmission delay= 10*2^20*8/10= 8.4*10^9 ms
latency= 6.67*10^-6+8.4*10^9= 8.4*10^9ms


#4) We will start working on a group project that implements “Interprocess communication using pipes”. Pipes is one of the ways to implement IPC. Write a blog that explains the functions needed to implement IPC using pipes and also those needed for communication using shared memory.


popen() : this begins another to send and receive data
pclose() : this ends the file stream that was opened
fread() : this is used to read data from the file opened by the popen
fwrite() : this is used to write data to the file
shmget() :  this allows us to accesses memory that is shared
shmctl() : this alters characteristics and permissions of a shared memory
shmat() :  this connects memory portions
shmdt() : this breaks memory portions



#5) fread and fwrite are C functions that can read bytes (instead of lines, or strings, char etc) from a file. Describe these functions and also write short programs that demonstrate them. 

fread: is used to read data from the file opened
fwrite: is used to write data to a file.
basically they do opposite jobs.

fread function: 
size_p fread(void *ptr, size_p size, size_p nmemb, FILE *stream);


fwrite function:

size_p fwrite(const void *ptr, size_p size, size_p nmemb, FILE *stream);












lab 2

3a
Transmission Delay:
m/r= 10mb/1gbps
10mb= 83886080bits
1gbps= 1000000000bits
m/r= 0.083886 ms

Propagation delay:
speed of light(C)= 299792458
2/3(c)= 199861639
36000/199861639= 0.000180126


Latency= 0.083886 + 0.000180126= 0.08406613

3b
Transmission Delay:
m/r= 10mb/10bps
10mb= 83886080bits
10bps= 10 bits
m/r= 838860

Propagation delay:
speed of light(C)= 299792458
2/3(c)= 199861639
2/199861639= 0.000000001000692


Latency= 0.000000001000692 + 838860= 838860.000000001


4

open- opens the function and makes the connection between a file and file descriptor.
connect- connects a function by attempting to connect to a socket
write- tries to write nbyte from the buffer pointed to the by buf to the file associated with the open file descriptor.
close- closes a file descriptor, that way it doesn't go back to any file and may be recycled.
read- tries to read to count bytes from file descriptor fd into the buffer starting at buf.
pipe- makes a pipe, a unidirectional daa channel that can be used for interprocess communication.







5 fwrite

#include <stdio.h>

struct clientData {
    int acctNum;
    char lastName[ 15 ];
    char firstName[ 10 ];
    double balance;
};


int main()
{
    FILE *cfPtr;
    struct clientData client = { 0, "", "", 0.0 };

    if ( ( cfPtr = fopen( "credit.dat", "r+" ) ) == NULL )
        printf( "File could not be opened.\n" );
    else {
        printf( "Enter account number "
               " ( 1 to 100, 0 to end input )\n? " );
        scanf( "%d", &client.acctNum );

        while ( client.acctNum != 0 ) {
            printf( "Enter lastname, firstname, balance\n? " );
            fscanf( stdin, "%s%s%lf", client.lastName, client.firstName, &client.balance );
            fseek( cfPtr, ( client.acctNum - 1 ) * sizeof( struct clientData ), SEEK_SET );
            fwrite( &client, sizeof( struct clientData ), 1, cfPtr );
            printf( "Enter account number\n? " );
            scanf( "%d", &client.acctNum );
        }

        fclose( cfPtr );
    }

    return 0;
}






fread

#include <stdio.h>

struct clientData {
    int acctNum;
    char lastName[ 15 ];
    char firstName[ 10 ];
    double balance;
};


int main()
{
    FILE *cfPtr;
    struct clientData client = { 0, "", "", 0.0 };

    if ( ( cfPtr = fopen( "credit.dat", "r" ) ) == NULL )
        printf( "File could not be opened.\n" );
    else {
        printf( "%-6s%-16s%-11s%10s\n", "Acct", "Last Name", "First Name", "Balance" );

        while ( !feof( cfPtr ) ) {
            fread( &client, sizeof( struct clientData ), 1, cfPtr );

            if ( client.acctNum != 0 )
                printf( "%-6d%-16s%-11s%10.2f\n",
                      client.acctNum, client.lastName,
                      client.firstName, client.balance );
        }

        fclose( cfPtr );
    }

    return 0;
}







lab #2


3) Consider a transmission link that is 36000m long and uses 1Gbps transmission speed. How long will it take to transmit a      10MB file along this link? Assume that the propagation speed is equal to the speed of light.

latency = m/r +d

transmission delay is m/r
m= 10 mb
r= 1 gps
Next i converted m to bits which is 83886080 b
and also r to bits per second which is 1,000,000,000 bps

these values are then divided to equal 0.08388608
i then mutliply by 1,000 to convert this which is 83.88608 ms

propagation delay =d
36000/speed of light
36000/299792458 =  0.000120083
i then converted this to get 0.120083074ms

latency = m/r +d
83.88608 + 0.120083074 = 84.00616307 ms
---------
2m long link and 10bps transmission rate
  =  (10 * 1048576) * 8 / 10
          = 8388608s
         = 8388608000ms
propagation delay= 2/c(speed of light)

2/299792458 = 0.0000000066728 seconds 
 then converted is 6.6728x10^-6

l=m/r +d
8388608000 + 6.6728*10^-6
-------------------------------------------------------------------------------
4) We will start working on a group project that implements "Interprocess communication using pipes". Pipes is one of the ways to implement IPC. Write a blog that explains the functions needed to implement IPC using pipes and also those needed for communication using shared memory.

pipe() creates a pipe, a unidirectional data channel that can be used for interprocess communication
write() is used to attempt to write nbyte bytes from the buffer pointed to by buf to the file associated with the open file descriptor
open() is able to open a function and establishes the connection between a file and a file descriptor
read() attempts to read up to count bytes from file descriptor fd into the buffer starting at buf.
connect() can connect a function by trying to connect to socket.
close() closes a file descriptor, so that it no longer refers to any file and may be reused.
----------
shared memory is one method of interprocess communication whereby 2 or more processes share a single chunk of memory to cummunicate.
shmget() provides access to shared memory by providing a shared memory segment ID on a successful call.
shmctl() from a controlling user/owner that already has permission to access shared memory allows another application to get the same access
shmat() used to allow access to shared memory once an ID has been received.

---------------------------------------------
5)
#include <stdio.h>
#include <string.h>

int main()
{
   FILE *fp;
   char h[] = "khem";
   char buffer[20];

   // Open file for both reading and writing 
   fp = fopen("test.txt", "w+");

   // Write data to the file 
   fwrite(h, strlen(h) + 1, 1, fp);

   // Seek to the beginning of the file 
   fseek(fp, SEEK_SET, 0);

   // Read and display data 
   fread(buffer, strlen(h)+1, 1, fp);
   printf("%s\n", buffer);
   fclose(fp);
   
   return(0);
}

















lab 2 answers

3a.

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/

Lab Assignment 2

3.)
  A)   length = 36,000
      Speed of signals = 10^9

Transmission Delay = M(bits)/R(bps)
10 MB = 83886080 bits / 1GB = 10^9 = 0.083 m/s



 Propagation Delay = D(seconds) so, formula for D = length / speed of signals.   36,000/10^9 =0.000036 m/s


Latency = M(bits)/R(bps)+D

10 MB = 83886080 bits / 1GB = 10^9 = 0.083 m/s , therefore 0.083+0.000036 = 0.084 m/s


B)
Transmission Delay = 10^6/10 =100000 m/s

Propagation Delay
 Length=                  2
                         ________ =  0.2 m/s

Speed of signal=     10 bps

Latency = 100000+0.2 = 100000.2 m/s

4.) IPC is a set of methods for the exchange of data among multiple threads.
the pipe() function provides a means of passing data between two programs and also allows to read and write the data.
#include<unistd.h>
int pipe(int file_descriptor[2]);
Return 0; // if an error Return -1;

Pipe Processing-
The process of passing data between two programs can be done with the help of popen() and pclose() functions.
#include<stdio.h>
FILE *popen(const char *command ,  
const char *open-mode);
int pclose(FILE *stream_to_close);
The popen function allows a program to declare another program as a new process and either writes the data to it or to read from it. To perform bi-directional communication you have to use two pipes.

By using pclose(), we can close the filestream associated with popen() after the process started by it has been finished. The pclose() will return the exit code of the process, which is to be closed.
Shared Memory Segment is a method of IPC that where two or more processes share a single chunk of memory to communicate.
#include<sys/shm.h>
void *shmat(int shm_id,
const void *shm_addr,int shmflg);

The first parameter is the shm_id,
identifier returned by the shmget.
The second parameter is the address at which the segment is to be attached to the current process. This will always be NULL pointer so that system can choose the address at which the memory is available.

The third parameter is the flag value. There are two possible flag values they are:
1.) SHM_RND-controls the address at which the segment is attached.
2.) SHM_RDONLY-makes the attachment read-only.
 


Source - http://developeriq.in/articles/2012/may/30/interprocess-communicationipc-programs-in-c-in-ubu/



5.) #include <stdio.h>

fread(void *buffer, size_t size, size_t num,FILE *fp);
{
.
.
.
return num;
}

 fwrite(void *buffer, size_t size, size_t num, FILE *fp);
{
.
.
.
 return num;
}

fread- reads a block memory or file and Fwrtites does the complete opposite of Fread.Fwrite creates a block into the file.

fp(stands for file pointer) is where you should write your file. Num is return because it is how many elements that were read and written. In Fread if
the number returned is  zero its either 1: no files has been read.
                               2: an error occured.

In Fwrite if the number of values written is less than num then an there is an error.