I see the system-ed perl as an autonomous process (unknowing of its parent process)
As you are probably aware, system is equivalent to fork followed by exec.
You are also probably aware tha fork preserves open file descriptors. This is why to create a daemon, it is necessary to fork twice. You fork once, close the standard handles in the child; and then fork a second time. Only then does the second child become disassociated with the terminal and a true daemon.
What you may not be familiar with is that (various forms of) exec are front end for execve. And that execve() also preserves open file descriptors. (Except those marked close-on-exec.)
To quote the above man page:By default, file descriptors remain open across an execve().
You can prove this to yourself. Run this one-liner (suitably adjusted):
perl -e"system qq[ $^X -e\"\$n=123; print \$n\" ];"
123
And you'll see the output 123
Now try this modified version: C:\test>perl -e"close STDOUT; system qq[ $^X -e\"$n=123; print \$n\" ]
+;"
Where did the output disappear to?
So bang goes the autonomous process theory.
In both cases, we're printing out a string with one character at codepoint U+00FF.
No. The return value from pack 'B8', ... is not a character; nor a codepoint; and absolutely nothing to do with Unicode.
It is a byte! An 8-bit unsigned number bit pattern stored in a 8-bit unit of memory and nothing else.
No interpretation of the meaning (nor even signedness) is placed (nor could be) upon that value until you do something with it!
The second system-ed perl has its output set ...
You're right that the interpretation applied to the 8-bit value is not preserved across the fork/exec pair, but not because of your reasoning.
The important part is that the OS cannot preserve what it has no knowledge of. There is no concept of encoding attached to the file descriptors.
It is also likely, though I haven't confirmed this, that Perl reopens the standard handles when it starts.
The bottom line -- for this thread, rather than this subthread -- is that the OP must have omitted some details from his scenario.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
|