SPUG: perl question...
Avinash Jaisinghani
avinashj at yahoo.com
Fri Jan 12 14:49:52 CST 2001
Or if you want a way w/o fork
you can run this as
$$ ./bgtest y
$$
<code>
#!/usr/local/bin/perl
my $isbg = @ARGV[0];
if ( $isbg eq 'y' ) {
system("path/to/bgtest &");
}
else {
main();
}
exit(0);
sub main {
# do stuff here
# blah here
}
</code>
Of course Matt's way is better.
-A
--- Matt Tucker <tuck at whistlingfish.net> wrote:
> -- Bhargava Vadapalli <Bhargava at drugstore.com> spake
> thusly:
>
> > I was wondering if anyone can help me run a perl
> program as a
> > background process.
> >
> > I am being lazy and asking you all instead of
> finding out for
> > myself...but hey why re-invent the wheel !!
>
> $ perl <scriptname> &
>
> or even:
>
> $ /path/to/script &
>
> Or did you want it to background itself?
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> exit &main();
>
> sub main {
> my $pid = fork;
> defined $pid or die "Can't fork";
> return 0 if $pid;
>
> # You could close stdout/stderr here if you
> wanted, and
> # send all output to syslog or something
>
> # <Do whatever needs doing>
>
> return 0;
> }
>
> ATTACHMENT part 2 application/pgp-signature
=====
asdfghjkl;'zxcvbnm,./qwertyuiop[]\
__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list