Think about Loose Coupling | |
PerlMonks |
Re: How do I fork a daemon process under Win32?by John M. Dlugosz (Monsignor) |
on Aug 14, 2001 at 10:11 UTC ( [id://104680]=note: print w/replies, xml ) | Need Help?? |
Huh? Win32 doesn't have a fork system command, and it's process model doesn't work that way. The current version of Perl uses ithreads to emulate fork to a useful degree. But the "parent" and the "child" are different instances of the Perl interpreter running in the same process. Detaching the child from the console and/or creating another console will affect the "parent", too!! In your example, you detach the parent before forking, and then immediatly block the parent. Why bother to fork? A more realistic example would be to have the parent continue running and outputting to STDOUT while the "deamon" runs in the background, and I think this will have problems. Don't use fork. The program that's a deamon can detach from the console, and the parent that started it (with system or Win32::CreateProcess) doesn't worry about that, and continues running normally. Also, you can specify flags in CreateProcess to run detached in the first place. Also, you can use wperl.exe instead of perl.exe and run in the GUI instead of the CONSOLE mode, so there is no console window at all.
In Section
Seekers of Perl Wisdom
|
|