How do I use fcntl on HPUX 9.0? 
Author Message
 How do I use fcntl on HPUX 9.0?

Quote:

> I am trying to understand how to use the unix fcntl commands F_GETLK,
> F_SETLKW, and F_SETLK with the perl fcntl function.  In particular,
> I don't understand how the perl SCALAR argument maps into the flock
> structure.  Also, when I look at the "sys/fcntl.ph" created by h2ph
> and c2ph, I see no code where the flock structure was defined.
> Should I see some corresponding perl code?  Could someone who has
> utilized this function explain it to me?
> Dave Hannum

I've posted this before - and got lightly toasted for using an explicit
argument to pack() - but my c2ph doesn't work :--( . Anyway it at least
demonstrates using fcntl to do file locking.

require('lock.pl');

then call &lockfile(FILEHANDLE) and &unlockfile(FILEHANDLE)
(FILHANDLE is an open filehandle
    (in case you hadn't guessed (:-) (yes, I *like* lisp :-)))

8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----

# routines for getting locks in the absence of the flock function
#
# $Id: lock.pl,v 1.2 1993/08/23 15:25:38 bill Exp $
#
#

sub lockfile {
    package locker;

    local ($package) = caller;
    local ($handle) = (eval "$package'$filename");
    select((select($handle), $|=1)[0]);
    fcntl($handle, $F_SETLKW, $lock);

Quote:
}

sub unlockfile {
    package locker;

    local ($package) = caller;
    local ($handle) = (eval "$package'$filename");
    fcntl($handle, $F_SETLK, $unlock);

Quote:
}

package locker;

require('sys/fcntl.ph');

$F_SETLKW = &F_SETLKW;
$F_SETLK = &F_SETLK;

$lock = pack('s s l l s', &F_WRLCK, 0, 0, 0, 0);
$unlock = pack('s s l l s', &F_UNLCK, 0, 0, 0, 0);

1;

8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----8<----
--

Cheers
        Bill

  ===========================================================================

 | C.L.I. Connect Ltd.               |                                       |
 | 19, Quarry St., Guildford, Surrey | If you think big enough, you'll never |
 | GU1 3UY. Tel (UK) 0483 300 200    | have to do it.                        |
  ===========================================================================



Mon, 06 May 1996 01:04:27 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. How do I use fcntl on HPUX 9.0?

2. installing Perl4.036 on HPUX 9.0 - HP9000/700

3. curseperl, HP 9000/8xx, HPUX 9.0

4. Making Perl on HPUX 9.0

5. Checking for open files using fcntl: flock in Solaris

6. Has anyone used Fcntl to handle file locking?

7. Req for example: file lock using fcntl

8. Help with using fcntl file locking

9. File locking using Fcntl

10. Using fcntl in perl

11. Piddly runtime error using DB_File and Fcntl

12. Nee file lock example using fcntl

 

 
Powered by phpBB® Forum Software