niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Perl » modules
problem with using the forks module within a daemon setting
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
Author Message
dszostek@gmail.com
*nix forums beginner


Joined: 16 Aug 2005
Posts: 19

PostPosted: Tue Jun 20, 2006 2:20 pm    Post subject: Re: problem with using the forks module within a daemon setting Reply with quote

Sorry Xho -- after I posted it here I thought it would be better in the
..misc group. I couldn't find how to delete it. I'll post there first
next time. Thanks for your help.

xhoster@gmail.com wrote:
Quote:
"Dave" <dszostek@gmail.com> wrote:
Hi,

I have a program that I have been running via cron that I thought might
be better run by running it as a daemon. When I created some test
daemon programs they all worked. When I placed my program inside of the
while loop, I noticed that the daemon killed its self somehow. I then
figured out that it died just after it tried launching a new fork
process -- and when I commented this out it worked fine.

Please don't multipost. See my response in comp.lang.perl.misc

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Back to top
xhoster@gmail.com
*nix forums Guru


Joined: 19 Jul 2005
Posts: 842

PostPosted: Tue Jun 20, 2006 12:03 am    Post subject: Re: problem with using the forks module within a daemon setting Reply with quote

"Dave" <dszostek@gmail.com> wrote:
Quote:
Hi,

I have a program that I have been running via cron that I thought might
be better run by running it as a daemon. When I created some test
daemon programs they all worked. When I placed my program inside of the
while loop, I noticed that the daemon killed its self somehow. I then
figured out that it died just after it tried launching a new fork
process -- and when I commented this out it worked fine.

Please don't multipost. See my response in comp.lang.perl.misc

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Back to top
dszostek@gmail.com
*nix forums beginner


Joined: 16 Aug 2005
Posts: 19

PostPosted: Mon Jun 19, 2006 7:13 pm    Post subject: problem with using the forks module within a daemon setting Reply with quote

Hi,

I have a program that I have been running via cron that I thought might
be better run by running it as a daemon. When I created some test
daemon programs they all worked. When I placed my program inside of the
while loop, I noticed that the daemon killed its self somehow. I then
figured out that it died just after it tried launching a new fork
process -- and when I commented this out it worked fine.

I made some sample code based on how I am doing this. I have it set to
print output to the screen. I have it below to not use threads. That
will let you see what it is supposed to do. Then, if you uncomment the
'use forks' statement, comment the line beginning with &browserbuilder,
and uncomment the line starting with ${$i}=threads you will see what it
does in a threads-based setup.

Can anyone provide any insight in to why this is not working and
perhaps give some advice for what I need to do?

Thanks,
~dave

PS> I would like to use forks instead of threads although I have them
both in the program for testing.

----------------------------


#!/usr/bin/perl

use POSIX qw(setsid);

&daemonize;

#use forks;
#use threads;
#uncomment one of two above modules to use that package for threading
use strict;

while(1) {

my (@urls,@urls2,$ib,$i);
$ib="a";
print "Started at " . `date` . "\n\n";

@urls=qw/1 2 3 4 5 6 7 8 9 10/;

foreach my $xurlid(@urls)
{

$i=$ib . $xurlid; #makes each thread object unique by adding
it's url id to '$ib' defined above
print "about to fork $xurlid thread\n";
#${$i}=threads->create(\&browserbuilder, $xurlid, 'dave');
#uncomment above to use thread-based setup
&browserbuilder($xurlid,'dave');
#uncomment above to use non-thread setup
push @urls2, $i; #used for checking thread status later
select(undef, undef, undef, 0.07); #sleep for 70 milliseconds
}

###########
# Go through each thread and wait for it to close so the program
doesn't exit early
#foreach my $url(@urls2)
# {
# @{$url} = ${$url}->join();
# print "$url returned: ${$url}[0]\n";
# }
###########
print "Ended at " . `date` . "\n\n";
sleep 10;
}
#end loop

sub browserbuilder
{

my $num=shift @_;
my $name=shift @_;

print "\n$name forked $num correctly\n\n";
return 0;

}

sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
# open STDOUT, '>>/var/log/uu_info.log' or die "Can't write to
/dev/null: $!";
open STDERR, '>>/var/log/uu_errors.log' or die "Can't write to
/dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
umask 0;
}
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [3 Posts] View previous topic :: View next topic
The time now is Sat Jan 10, 2009 12:35 am | All times are GMT
navigation Forum index » Programming » Perl » modules
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Unknown in header problem -SOLVED- Light Speed Postfix 0 Thu Jul 03, 2008 10:40 am
No new posts problem with sending mail nuxia Postfix 0 Mon Apr 21, 2008 3:58 am
No new posts Postfix 2.3.8 Virtual problem Blotto Postfix 0 Fri Apr 04, 2008 6:11 am
No new posts Postfix sending problem for local domain remote email monkey_magix Postfix 0 Mon Sep 10, 2007 10:17 am
No new posts bounce problem murkis Postfix 0 Sun Oct 08, 2006 3:45 pm

Mortgage Calculator | Loans | Fashion Jewelry | Credit Cards | Internet Advertising
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2911s ][ Queries: 20 (0.1976s) ][ GZIP on - Debug on ]