#Lock my file... # Use LOCK_SH because I don't want the second thread to be able # to read until I'm done. flock( OUTFILE, LOCK_SH); seek( OUTFILE, 0, 2); # Why do I need this line? # Read from OUTFILE and if it has the right value then go ahead and # write the new value into it to indicate that the second process # should do something different, otherwise you are the second # process... unlock and do something different. # Now unlock... flock( OUTFILE, LOCK_UN);