Teddy -- ...and then Octavian Rasnita said... % % Hi all,
Hello again! % % I am a beginner in Perl, and in the first lessons of some manuals I haven't % seen anything about how to run a Perl script in background. % Is it something very complicated? Well, it depends on what you want to do. If you're at a shell prompt you could just /path/to/script.pl & and there you go (with perhaps a nohup if you're running Bourne shell). It's in the background and, with some shell job control, you can even exit. Then there's the matter of forking off a process so it disassociates itself from any terminal, which is what you want. % % If it is, then I will wait a little to learn Perl better. % If it is not too complicated, can you give me some hints about what should I % do to run a Perl script in bacground? % % I want to leave the program running on the server and to close the browser % without closing the program. That shouldn't be too tough. Check the docs and the camel book for fork. Basically what you do is you write your code so that you set up what you need (any variables or the like) and then call the fork function, which makes a copy of the process and sets it off on its own (with a new PID, that is, and I think with no filehandles). In your code you suddenly can't tell whether you're the parent or the child, so right after the fork you do a simple if test to see which you are; fork function returns 0 to the child process and a PID (which can never be 0) to the parent process. It could look about like ... code code if ( $result = fork ) { print "I am the parent. Take wing, my child!\n"; print $webmessage; exit 0 } elsif (defined $result ) { print "I am the child; away we go\n"; code code loop { forever } } else { print "fork bombed!\n"; exit 99 } according to the camel book... % % Thank you. HTH & HAND % % Teddy, % [EMAIL PROTECTED] :-D -- David T-G * It's easier to fight for one's principles (play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie (work) [EMAIL PROTECTED] http://www.justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
msg05300/pgp00000.pgp
Description: PGP signature