Perl multi-Process read-write text

Source: Internet
Author: User
Tags flock

Using Perl to dispatch SQL scripts, in the process of opening a number of processes, I found that Perl write log file order disorder, do not want to engage in multi-threading programming so troublesome, my processing method, the corresponding file lock. Perl provides the Flock function to lock the file handle.

Reference code:

Use Fcntl QW (: flock);
My $sum;
My $kk = $ARGV [0];
Open WR, ">>/wls/dsadm/etl/test.txt";
Flock (WR, LOCK_EX);
for ($i =1; $i <=80000; $i + +)
{
$sum = $i;
print "$sum \ n";
Print WR $sum. $kk. " \ n ";
}
Flock (WR, LOCK_EX);

Close WR;


Note: Fcntl is the status value of the Get file.

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.