From:	SMTP%"lchen@nimbus.ocis.temple.edu" 28-OCT-1996 11:23:29.25
To:	ingargiola@falcon.cis.temple.edu
CC:	
Subj:	lab report


This is my lab report:


   1  File locking: ( mandantory and advisory locking)
  
      int fcntl (int filedes, int cmd, struct flock *flockptr);
       
      struct flock {
          short l_type;
          off_t l_start;
          short l_whence;
          off_t l_len;
                   }

      example :

          set a write lock:

          #include 
          #include 

          int lock_reg(int fd, int cmd, int type, off_t offset,
                         int whence off_t len)
            {
               struct flock lock;

               lock.l_type=type;
               lock.l_start=offset;
               lock.l_whence=whence;      
               lock.l_len=len;
               return (fcntl (fd, cmd, &lock));
             }

       // a write lock:

             lock_reg(fd, F_SETLK, FWRLCK, offset, whence, len);


        about flock:


           #include 
     
            int main() 
             {
                int fd;

                if ((fd=open("lock", O_RDWR|O_CREAT))<0)
                      {
                         perror("open error");
                         exit(1);
                flock(fd, LOCK_EX);
           
                 ....

                flock(fd, LOCK_UN);
                exit(0);
               }


          shared memory:

             #include 

             int shmget(key_t key, int size, int flag);

               eg:  shmid=shmget(IPC_PRIVATE, sizeof(char), SHM_R|SHM_W);

             void *shmat(int shmid, void *addr, int flag);

               eg:   p=(char *)shmat(shmid, 0, 0);

             int shmctl(int shmid, int cmd, struct shmid_ds *buf);

               eg: shmctl(shmid, IPC_RMID, 0);

    PS:  Since most of the students in section 1 are working on their
         2nd homework, I will give them more detailed example about 
         shared memory in next week.
 
       The example on your notes is a good one , so I will talk about
  it to section 2 students tomorrow.