[TriLUG] Fwd: Why do File IO event seem to be out-of-order in strace?

Scott Lambdin via TriLUG trilug at trilug.org
Tue Sep 15 13:29:53 EDT 2015


Hi -

Just letting you know that I found out the forks are required for the test
program.  Each process can only lock one byte range, in order to avoid
something called "Dreadlocks"

--Scott

---------- Forwarded message ----------
From: Igor Partola via TriLUG <trilug at trilug.org>
Date: Tue, Sep 8, 2015 at 4:33 PM
Subject: Re: [TriLUG] Why do File IO event seem to be out-of-order in
strace?
To: Triangle Linux Users Group General Discussion <trilug at trilug.org>


Looks to me like you are doing fork() incorrectly:

 if(childPID >= 0) // fork was successful
    {
        if(childPID == 0) // child process
        {

This code after the above statement will run for both parent and child.
Since you are doing this in a loop the second process you fork will inherit
the parent's lock.

The correct way to write this would be like so:

childPID = fork();

if (childPID < 0) {
    puts("Could not fork!");
    abort(1);
}

if (childPID == 0) {
    // Do the lock test.
}

if (childPID > 0) {
     // Spawn more children or wait on existing children to exit.
}


For your test, you don't need to fork(). Simply have a program that does
the locking with a 10 second sleep before unlocking it. Fire off this same
program twice and watch the second one take longer than 10 seconds while it
waits for the lock.

Igor
--
This message was sent to: Scott Lambdin <lopaki at gmail.com>
To unsubscribe, send a blank message to trilug-leave at trilug.org from that
address.
TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
Unsubscribe or edit options on the web  :
http://www.trilug.org/mailman/options/trilug/lopaki%40gmail.com
Welcome to TriLUG: http://trilug.org/welcome



-- 

Eat like you give a damn.  Go vegan.


More information about the TriLUG mailing list