Your attempt at making a semaphore file is not having any effect. The race condition caused by reading and writing separately goes like this:
| Process A | Process B |
| 1 | readdata() | |
| 2 | | readdata() |
| 3 | | writedata() |
| 4 | writedata() | |
Process B's work is overwritten.
You should open the file once to read and write, flock it (blocking), read, process, and write. Close releases the lock.
To use a semaphore file, you should do a blocking sysopen with O_EXCL, and unlink the file when you're done. There's no need to use both methods.
I think you also have a problem with autovivifying globals in your subroutines, then expecting later lexicals to appear in their place. use warnings; use strict;.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.