Menu

#24 Forked Process's Handle reports the Parent's PID

Unstable (example)
open
5
2008-08-26
2008-08-19
Michael
No

When a Parent Process registers with STAF prior to Forking a Child Process, the PID in the Child's Handle information is incorrect. It shows the PID of the Parent.

The Parent knows the PID of the Child, and the Parent queries the Handle Service until the Child's PID is seen in the PID field (or times out) so that the Parent and Child can communicate via the Queue Service.

To preemptively answer a few questions:
Yes, I know we could look for the Registered Name, but in (our) reality, the registered Name of the Forked child is not as deterministic as I have shown in the attached example.

No, We can not always use the Process Service to spawn new Processes. We need fork to spawn legacy code references.

To see the problem I’m trying to explain, run the attached “Perl_Fork.pl” file.

In the example:
1. The Parent forks a child
a. The forked Child Registers with STAF
b. The Child does a “Handle Query …” on it’s handle
c. The information will be accurate because the Parent has Not registered with STAF yet
2. The Parent Waits for the child to complete
3. The Parent Registers with STAF
4. The Parent does a “Handle Query …” on it’s handle (which is accurate)
5. The Parent forks another child
a. This forked Child Registers with STAF
b. This Child does a “Handle Query …” on it’s handle
c. The information will Not be accurate because the PID in the Parent’s scope has been cached and inherited (I guess) when this child registers with STAF

Discussion

  • Michael

    Michael - 2008-08-19

    removing the Caching from STAFUtilCommon.cpp STAFUtilGetPID()

     
  • Michael

    Michael - 2008-08-19

    Example script

     
  • Michael

    Michael - 2008-08-19

    Logged In: YES
    user_id=1893390
    Originator: YES

    File Added: Perl_Fork.pl

     
  • Michael

    Michael - 2008-08-22

    Logged In: YES
    user_id=1893390
    Originator: YES

    I forgot to mention that this Patch is Primarily for Non-Windows (Linux/Unix) since forked processes on Windows have a virtual PID instead of a real PID. It has no ill effect on Windows.

    ....

    I've tested this code on:
    Windows: XP, Win2k3, Vista, and Server2k8
    Linux: redhat8, rhel4 (32 & 64 bit), rhel5 (32 & 64 bit), and some SuSe (I don't remember the architecture)
    Solaris: 5.9 (i386 & sparc), 5.10 (i386 & sparc)

     
  • Sharon Lucas

    Sharon Lucas - 2008-08-26
    • assigned_to: nobody --> slucas
     

Log in to post a comment.

MongoDB Logo MongoDB