Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re: getting a child's process ID

by blackmateria (Chaplain)
on Oct 19, 2001 at 22:43 UTC ( [id://120108]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: getting a child's process ID
in thread getting a child's process ID

Seshouan, I just re-read the posts in this thread again, and enlightenment struck me like a ton of bricks (I think ;) Are you using ActivePerl on Windows? Because in that version of perl, process ID's don't stay the same across an exec() call. The PID is supposed to stay the same, and on Unix, it does; that's why davorg's example works and yours doesn't -- he tried his on Unix.

The problem is, Win32 doesn't have a way to launch a new program without changing the PID. On Unix, exec() is an actual system call that loads a new program into a pre-existing process. On Win32, exec() is implemented by having the exec-ing process call CreateProcess, and then exit. So on Unix the $pid=fork trick works because the program you are exec-ing ends up in the child you created with fork, but on Windows, the program you exec ends up as a grandchild of the original process. Oops. That will make things a lot harder.

I can think of two ways to solve this problem: (1) use Cygwin's Win32 perl instead of ActivePerl, or (2) hack together some kind of inter-process communication to let the parent process find out the child's pid. For example, pass the child a command-line argument that's a filename where it can write its pid once it starts up. Unfortunately, both these solutions require that you're in control of both the exec'd child and the parent. If not, there's probably still something you can do to get the child's pid, but I can't think of it off the top of my head. And of course all of this is irrelevant if you're not actually running on Win32. Anyway, good luck.

  • Comment on Re: Re: Re: getting a child's process ID

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://120108]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 07:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found