in reply to Sharing STDIN after fork

The STDIN filehandle is shared between your two processes, and as you already noticed, whatever process comes first reads it all.

You could set a flag to specify, which process should read STDIN, or you could read all of STDIN and then call fork().

Replies are listed 'Best First'.
Re^2: Sharing STDIN after fork
by Bod (Parson) on Feb 13, 2022 at 22:27 UTC

    Thanks Corion

    Does it make any difference which process is used for which operation or are they interchangeable?

      No, both processes are almost identical - the only difference when they start out is the result of the call to [func://fork].

      Usually, the web server will wait for the original program, not the forked copy, to finish before considering the HTTP call complete, so you might want to put long-running stuff into the child. The child process is the one with a zero from fork().