Re: Leave it running
by edan (Curate) on Dec 04, 2003 at 06:01 UTC
|
shell> nohup kevins_perl_script.pl &
Your script's output will be in a file called nohup.out
| [reply] [d/l] |
|
| [reply] |
Re: Leave it running
by QM (Parson) on Dec 04, 2003 at 06:39 UTC
|
You may also be interested in screen, which allows you to "detach" the terminal from the process, and "reattach" to the process later from the same or another terminal (on the same machine).
-QM
--
Quantum Mechanics: The dreams stuff is made of
| [reply] |
Screen
by barbie (Deacon) on Dec 04, 2003 at 06:42 UTC
|
| [reply] |
Re: Leave it running
by Zaxo (Archbishop) on Dec 04, 2003 at 06:03 UTC
|
See man nohup or else your script can remove itself from its controlling terminal with &POSIX::setsid. You should also make sure that the script runs from the system root directory, since it will not be unmounted.
| [reply] |
Re: Leave it running
by Roger (Parson) on Dec 04, 2003 at 06:02 UTC
|
nohup script.pl args... &
| [reply] [d/l] |
Re: Leave it running
by Anonymous Monk on Dec 04, 2003 at 06:51 UTC
|
my webhost sucks....I have had to manually install all of my own perl modules in my own library (since I don't have root priveledge, thanks to perlmonks for showing me how). My system does not have a lot of stuff installed already. man screen does not work, this sucks, I hate my webhost.
-Kevin | [reply] |
|
You may have luck installing screen on your own, since it is available through this link.
-QM
--
Quantum Mechanics: The dreams stuff is made of
| [reply] |
|
nohup doesn't work either!
-Kevin
| [reply] |
|
Try this, inside your perl script:
$SIG{HUP} = 'IGNORE';
Then try running it in the background (script.pl &).
Or, to act like a real daemon process, read perlipc under the 'Complete Dissociation of Child from Parent' section.
| [reply] [d/l] |
Re: Leave it running
by Anonymous Monk on Dec 04, 2003 at 06:35 UTC
|
my system does not recoginize the command nohup. | [reply] |
|
If you can't use nohup for some reason then you can still "daemonize" your script.
Someone mentioned POSIX::setsid() - I have had good luck with using the following subroutine:
sub daemonize {
my $childpid;
if(($childpid = fork()) < 0) {
die("can't fork: $!");
} elsif($childpid > 0) {
exit(0); # parent - exits
}
(setpgrp() != -1) || die("Can't change process group: $!");
$SIG{HUP} = 'IGNORE';
if(($childpid = fork()) < 0) {
die("can't fork: $!");
} elsif($childpid > 0) {
exit(0); # parent - exits
}
chdir("/");
umask(0);
}
This code was borrowed from Stevens' "Unix Network Programming" - a book that should be in every programmers bookshelf...
Michael
| [reply] [d/l] |
Re: Leave it running
by Anonymous Monk on Dec 05, 2003 at 00:01 UTC
|
I used the $SIG{HUP}='IGNORE'; method. I logged off an logged back on, the script is running (For some reason 'ps' doesn't work on my machine so I can see it, but it is doing work.)
It does not seem to be outputting to it's normal output file though, And there is not a nohup file.
-Kevin | [reply] |