John V. Pataki wrote:
> Bill,
>
> The code works fine as a standalone script... however
> it doesn't accomplish the task of letting the parent
> die off...
>
> I looked at the docs for fork() and found this tidbit:
>
> If the parent process is killed (either using Perl's
> kill() builtin, or using some external means) all the
> pseudo-processes are killed as well, and the whole
> process exits
>
> - This is what i need to avoid. I want the parent to
> exit and go away to free the calling application ...
> to fool it into thinking that the process died ... but
> really have my app start again as a cloned, not a
> child process.
>
> Any clues?
Well, if you need the orig script to die for some reason, then the exec
should handle that. I don't really understand the why of it all.
You could also use Win32::Process::Create and specify DETACHED_PROCESS
for the 5th arg and then just exit the orig script (I think that
should work for you also).
my $Obj;
Win32::Process::Create($Obj,
"C:/perl/bin/perl.exe",
"perl $0 fubar barfu",
0,
DETACHED_PROCESS,
'.') or die "Win32::Process::Create: $!";
>>John V. Pataki wrote:
>>
>>
>>>I need to run my perl program as a clone because I
>>
>>am
>>
>>>calling it from within another application that
>>
>>intend
>>
>>>to talk back to. The application's execute command
>>>wants to wait until the call to perl program is
>>>finished before continuing.
>>>
>>>I had this working at one time and now it seems to
>>
>>not
>>
>>>work ( I dredged up some old code from an older
>>>project ). I think it is actually running a new
>>>version of the program but it is not accepting a
>>
>>value
>>
>>>I pass it to test whether it is really a clone or
>>
>>not.
>>
>>>
>>>Here is what I have (that used to work at one
>>
>>time):
>>
>>>BEGIN {
>>> if ($ARGV[0] !~ /^-/) {
>>> if ($^O =~ /MSWin32/i) {
>>> if ($ARGV[0] ne "clone") {
>>> exec("$0 clone @ARGV") or die "Couldn't clone
>>>myself. $!\n";
>>> } # end if
>>> if ($ARGV[0] eq "clone") {print
>>
>>"CLONED!\n";shift
>>
>>>@ARGV};
>>> } # end if
>>> else {
>>> if ($pid = fork) {sleep 1;exit;};
>>> if (! defined $pid) {die "Couldn't clone
>>
>>myself.
>>
>>>$!\n"};
>>> } # end else
>>> } # end if
>>>} # end block
>>>
>>>
>>>
>>>I am not getting the message that it couldn't
>>
>>clone
>>
>>>itself - I am just getting continously re-starting
>>
>>of
>>
>>>the program ... so that tells me the pseudo-clone
>>
>>is
>>
>>>working but my test is failing...
>>>
>>>Any clues on what I am missing?
>>
>>fork should work on later versions of Win32 (at
>>least kinda).
>>Try soimething like this for a test :
>>
>>use strict;
>>
>>my $pid = fork;
>>die "fork failed: $!" if not defined $pid;
>>
>>if ($pid == 0) {
>> print "I am the clone\n";
>> print "[EMAIL PROTECTED]";
>> sleep 10;
>> exit 99;
>>} else {
>> print "I cloned $pid\n";
>> print "[EMAIL PROTECTED]";
>> waitpid $pid, 0;
>> print "Clone returned $?\n";
>>}
>>
>>__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs