TheYoungMonk has asked for the wisdom of the Perl Monks concerning the following question:

I have a simple code that forks a child process.
#!/usr/bin/perl my $pid = fork; if ($pid == 0) { # Child process print "Inside child process\n"; exit 1; } elsif ( $pid > 0 ) { # Parent process print "Inside parent process\n"; } else { # fork error print "ERROR! PID : $pid \n"; exit 1; }
On running this under Windows 2000 on a Pentium 4 system, it gave the following error:

The Unsupported function fork function is unimplemented

Is fork not supported on Windows 2000 ? Please do clarify..and enlighten this young monk

Replies are listed 'Best First'.
Re: perl fork cmd on Windows 2000
by tachyon (Chancellor) on Dec 17, 2002 at 09:36 UTC

    You have an old or crappy version of Perl. Get 5.6.1 from ActiveState here. Don't get 5.8 it is too new and untested. You should know that fork() on Windows is an emulation and not really production grade. Better thread support is included in 5.8 but this has only been recently released and does have some issues....

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      The build of perl i'm using was developed to specifically suit the application i'm working on. So, it is not feasible to change completely to the build provided by Activestate. Plz...Can some more workarounds or codes be suggested by The Monk Community?

      Pardon if this young monk is overstating.. I heard theres a library to handle proccesses and spawn child processes with Create, Wait etc. in win32-perl. Does anyone have more details or code segments to give a better idea abt this??

      tachyon..Thanks anyway for ur suggestion. The fork code does work under Active PERL !

        You can spawn off another process using Win32::Process. Below is some code I used to open a file in Notepad from a Tk program. Win32::Process is documented pretty well and there are plenty of examples out there. As other monks have stated, I'd be very wary of using fork with Perl on Windows. I've experimented with fork some on Windows and it seems like if you created more than a couple processes, it would crash in various ways.

        my $ProcessObj; Win32::Process::Create($ProcessObj, 'C:/WINNT/notepad.exe', "notepad $file", 0, NORMAL_PRIORITY_CLASS, ".")|| die "Couldn't open the file $file\n";

        «Rich36»

        The build of perl i'm using was developed to specifically suit the application i'm working on.

        That's an interesting idea. Normally I write software to fit within the framework of the language rather than modify the language.....With a languague as internally complex as Perl 5 you really have to wonder who thought that was a good idea and why?

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: perl fork cmd on Windows 2000
by mce (Curate) on Dec 17, 2002 at 13:55 UTC
    I just read a node about forking on unix and windows (sorry, I cannot recall it) that had a very nice link to this.

    This should explain it all.


    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium

Re: perl fork cmd on Windows 2000
by PodMaster (Abbot) on Dec 17, 2002 at 22:34 UTC

    Which version of perl do you have?

    What does perl -V say?

    If you have perl 5.6.1, and perl -V says:
    Compile-time options: MULTIPLICITY USE_ITHREADS PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
    you got fork, otherwise you dont.

    It is possible to compile perl yourself (non-activeperl flavor) and get fork() emulation (i've done it, just edit the Makefile -- look for ActivePerl, or just set BUILD_FLAVOR = ActivePerl).


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.