Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Answer: How do I fork a daemon process under Win32?

by tachyon (Chancellor)
on Aug 14, 2001 at 05:59 UTC ( #104658=categorized answer: print w/replies, xml ) Need Help??

Q&A > programs and processes > How do I fork a daemon process under Win32? - Answer contributed by tachyon

You can use Win32::Console to fork a detached/daemon process. Here is a little alarm clock example. When it runs it pops a console and asks for a sleep time. It then detaches from the console which closes. Next it forks. The parent just exits whilst the child sleeps for x seconds, pops a new console window and prints a message (just to prove it is alive and kicking). This new console disappears when the child exits 5 seconds later.
#!/usr/bin/perl -w use strict; use Win32::Console; my $con = Win32::Console->new(); $con->Display; $con->Write("Sleep how many seconds? "); chomp(my $sleep = <STDIN>); $con->Free(); # detache our script from the console which closes # now let's fork of an alarm clock child defined ( my $pid = fork() ) or die "Can't fork $!\n"; if ($pid) { exit; } else { sleep $sleep; $con->Alloc() or die $!; $con->Write("BZZT - this is your wake up call"); sleep 5; exit; }

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2019-11-14 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (76 votes). Check out past polls.

    Notices?