in reply to exec()ed process dont write to std(?:err|out)

the first perl immediately exits

Yes, exec ends the life of the executable that calls it, as documented. On systems that don't have fork, a call to exec spawns a subprocess and then tells the parent process to exit. If you want the grandparent (the process that started the process that ends up calling exec) to wait for the exec'd program to finish, then you need to have the middle process hang around.

On systems with fork, using exec works for that since the running executable is replaced with the new executable in the same process. On systems without fork, if you want to wait, then you should just use system then exit.

- tye        

  • Comment on Re: exec()ed process dont write to std(?:err|out) (system)

Replies are listed 'Best First'.
Re: Re: exec()ed process dont write to std(?:err|out) (system)
by demerphq (Chancellor) on Apr 13, 2004 at 15:06 UTC

    Ok, and just to make this clear, Win32 simulates fork, and is thus in the category where it doesnt have a fork right?

    If I do use system am I going to be wasting a lot of resources by having an outer normal perl running a system() call to another perl invocation? Also in your opinion is this a bad idea?


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


      Yes, Win32 doesn't have fork.

      Since most uses of system() (which are done outside of Perl, I'd guess) end up calling /bin/sh just to interpret the command-line syntax and then have /bin/sh just sitting around the entire time waiting for the program you really wanted to run to exit, I don't think it can be too awful to have a similar situation with perl sitting around.

      As for the bigger picture of what you are really trying to do, I won't pretend to understand it.

      - tye        

        As for the bigger picture of what you are really trying to do, I won't pretend to understand it.

        Oh sorry. The idea is so that when I have a bunch of scripts running I can see which perl is running which script in the process view of the task manager. For instance I may have 5 or 6 different scripts running at various points at the day. When I view the task manager I can only see say three "perl.exe"'s running, with no easy way to know _what_ they are running. So if one of them goes nuts I know which task to kill for example.


        ---
        demerphq

          First they ignore you, then they laugh at you, then they fight you, then you win.
          -- Gandhi