Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- PERL 4.0 Reference Guide - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

     flock(FILEHANDLE,OPERATION)

             Calls flock(2) on FILEHANDLE.  See manual  page  for
             flock(2)  for definition of OPERATION.  Returns true
             for success, false on failure.  Will produce a fatal
             error  if  used  on a machine that doesn't implement
             flock(2).  Here's a mailbox appender  for  BSD  sys-
             tems.

                  $LOCK_SH = 1;
                  $LOCK_EX = 2;
                  $LOCK_NB = 4;
                  $LOCK_UN = 8;

                  sub lock {
                      flock(MBOX,$LOCK_EX);
                      # and, in case someone appended
                      # while we were waiting...
                      seek(MBOX, 0, 2);
                  }

                  sub unlock {
                      flock(MBOX,$LOCK_UN);
                  }

                  open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
                       || die "Can't open mailbox: $!";

                  do lock();
                  print MBOX $msg,"\n\n";
                  do unlock();

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson