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

Scott Lambdin via TriLUG trilug at trilug.org
Wed Sep 9 12:39:26 EDT 2015


Yes, your way is better structure but the way I have it does the same
thing.  Will change it to your way so that my fingers learn it.

Thanks

Scott

On Tue, Sep 8, 2015 at 4:33 PM, Igor Partola via TriLUG <trilug at trilug.org>
wrote:

> 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