Q&A > programs and processes
Answer: How do I fork a daemon process under Win32? contributed by John M. Dlugosz 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.
|
Answer: How do I fork a daemon process under Win32? 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.
|
Please (register and) log in if you wish to add an answer
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |