HELP! File lock not preserved across an exec() ?!

HELP! File lock not preserved across an exec() ?!

Post by Eryq » Wed, 07 Aug 1996 04:00:00



Perl 5.002, Linux 1.2.13:

I came up with a really nice piece of Perl code for forking
off an external process and being able to check, reliably, at any
time, whether that process has died... basically, the parent
does a double-fork, and the grandchild establishes an exclusive
lock (LOCK_EX) on a file descriptor opened by the parent.  The parent
then checks on the child simply by trying to get a lock
(LOCK_SH|LOCK_NB) on that file descriptor.

Now, in Unix, we have the following:

        * Locks aren't preserved across a fork (which is why
          I open the LOCK_EX in the grandchild)

        * Locks *ARE* preserved across an exec(), and...

        * Open file descriptors *ARE* preserved across both
          a fork and an exec().

However, in my Perl code, it's clear that the grandchild has the
lock ONLY SO LONG AS IT DOESN'T EXEC ANOTHER PROGRAM... once I
call exec(), like this:

        exec $progpath, $arg1, ..., $argn;

I lose the lock!  It doesn't matter whether the thing I exec
is a Perl or /bin/sh script.   And yes, I did check, and the
close-on-exec flag is *not* set.

Can someone tell me if there's something BLINDINGLY OBVIOUS
I'm missing, or does Perl do a silent fork() (which would lose
the lock) inside exec(), or what?

I notice that under Linux, vfork() is a synonym for fork(), which
is listed (rightly so) as a bug (they behave very differently)...
could this issue be screwing Perl up???

HELP!
--
   ____           __

 / __/ _/ / / , /     Hughes STX, NASA/Goddard Space Flight Cntr.
/___/_/ \  /\  /___
        /_/ /_____/   http://www.mcs.net/~eryq

 
 
 

HELP! File lock not preserved across an exec() ?!

Post by jared sti » Sat, 10 Aug 1996 04:00:00



>Perl 5.002, Linux 1.2.13:
>I came up with a really nice piece of Perl code for forking
>off an external process and being able to check, reliably, at any
>time, whether that process has died... basically, the parent
>does a double-fork, and the grandchild establishes an exclusive
>lock (LOCK_EX) on a file descriptor opened by the parent.  The parent
>then checks on the child simply by trying to get a lock

<SNIP>

>I notice that under Linux, vfork() is a synonym for fork(), which
>is listed (rightly so) as a bug (they behave very differently)...
>could this issue be screwing Perl up???
>HELP!
>--
>   ____           __


Why not synchronize with a semaphore?

jared still                  ---- ___o

                       -----   (*)/o (*)
--------------------------------------

 
 
 

1. Accepted socket preserved across exec() ?

I'm working with TCP/IP sockets for the first time, and i've established
a working example client/server pair in which the server accepts the
client's socket connection and forks.  The child process then handles
the requested task and exits.  This works fine, with all the parent/child
code contained within the server executable.

What I would like to do, now, is have the server (daemon) accept the
connection, then fork() and exec() a seperate server executable to
handle the clients needs.  I thought the open file descriptors were
preserved across exec() calls, but after the parent closes the accepted
socket descriptor, the client loses the connection.

can anyone help?

Thanks, if you can...

2. connecting a Win2K client to a remote server

3. Help! File Locking Across NFS

4. NISGINA

5. Question: File Locking across NFS

6. unlink cputime

7. nfs very slow, locking files across nfs ?

8. XF86Config for CTX-1565GM ?

9. File Locking across NFS mounts

10. File Locking Across NFS

11. Fatal Server Error: Could not create lock file in /tmp/.tX0-lock???

12. HELP: FTP Not Preserving Dates (NT to AIX)

13. What's the difference between in Exec and Exec exec ...