in reply to Re: Re: main script invoked twice
in thread main script invoked twice
so the both the parent and the child process are printing the value as it was computed in the parent process.print "PID is $$"; fork(); ... # that is (or can be) essentially the same as: $buffer = ">> PID is $$"; fork(); print $buffer;
Get it?
Anyway, after looking at what you just had to say about the script re-exec'ing itself, it seems obvious that what is happening is not caused by the phenomenon I was describing (the pid getting caught in the output buffer at time of fork and thereby getting printed twice). The problem is that you are exec'ing the same script again from within the same process (so it's the same pid, even though it's a fresh run of the program).
Understand how exec works: it replaces the contents of the current process with a new program... but it retains the same process (hence the same pid). Exec is, essentially, loading the new program into the current process's memory and calling goto(begin). Now, that means that if you exec the same program that you call you exec from, then it's essentially just pressing the reset-button on your program (but, again, from within the same process, hence the same pid).
Hope that helps.
------------ :Wq Not an editor command: Wq
|
|---|