- 论坛徽章:
- 0
|
如果您对Daemon程序不是很了解,请先看看这里:
http://dev.csdn.net/article/42/42281.shtm
下面是我写的perl daemon的示例,功能与上面文章中的一样。希望大家不要对perl写daemon程序再感陌生,同时也希望板主能加到精华中方便查找。
- #!/usr/bin/perl -w
- # a daemon simple
- use strict;
- # become daemon
- my $pid = fork();
- print $pid,"\n";
- if($pid) {
- #end parent process
- print "#parent process";
- exit(0);
- }else {
- print "#child process";
- }
- # set new process group
- setpgrp;
- while(1) {
- sleep(30);
- open ("TEST",">;>;/tmp/test.log");
- my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
- $year+=1900;$mon++;
- print TEST ("Now is $year-$mon-$mday $hour:$min:$sec.\n");
- close (TEST);
- }
复制代码
以上程序在Red Hat Linux release 7.3 perl v5.6.1上测试通过。 |
|