Perl multi-process file lock

Source: Internet
Author: User

Fcntl filehandle, function, scalar

Implements the fcntl (2) function. You'll probably have to say

 
 Use Fcntl;

First to get the correct constant definitions. Argument processing and value returned work just likeIOCTLBelow. For example:

  use     fcntl  ; 
fcntl ( $ filehandle , f_getfl , $ packed_return_buffer )
or die " can't fcntl f_getfl: $! " ;

You don't have to checkDefinedOn the return fromFcntl. LikeIOCTL, It maps0Return from the system call"0 but true"In Perl. This string is true in Boolean context and0In numeric context. It is also exempt from the normal-WWarnings on improper Numeric conversions.

Note thatFcntlRaises an exception if used on a machine that doesn't implement fcntl (2). See the fcntl module or your fcntl (2) manpage to learn what functions are available on your system.

Here's an example of setting a filehandle namedRemoteTo be non-blocking at the system level. You'll have to negotiate$ |On your own, though.

 Use     Fcntl  QW (f_getfl f_setfl o_nonblock );
$ Flags = Fcntl (Remote , F_getfl , 0 )
Or Die " Can't get flags for the socket: $! \ N " ;
$ Flags = Fcntl (Remote , F_setfl , $ Flags | O_nonblock)
Or Die " Can't set flags for the socket: $! \ N " ;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.