Page 1 of 1

perl question using system() and sleep() problem

Posted: Fri Oct 06, 2006 3:50 pm
by ynn
Hi,

I want to ask you guys, how to run my_program.pl without interupting or
stoping the sleep() below, because what happened was the sleep stops
doing its job waiting for the system("my_program.pl") to be completed.
i tried using exec but exec stop the sleep right away.

Thanks for any help.

while(1) {
system ( "my_program.pl" );
sleep 60;
}

Posted: Mon Oct 09, 2006 4:07 pm
by zoneminder
What are you trying to get you program to do?

There are 3 ways I do process spawning stuff (1) Use system, I hardly ever use this (2) use `<command>` or qx, I use this for most things or (3) if you want to do something else while the command is being run or to limit a wait, use fork and exec. Without knowing what you want it to do I can't recommend which to use.

You could also use perlthreads if you are feeling brave :shock:

Posted: Mon Oct 09, 2006 4:27 pm
by ynn
Thanks for the reply, I am trying to start another daemon program if the time meets. this is cronlike program, so for example, if the time is equal to midnight, my daemon script would be run. so right now i am using system(), but the bad thing about system() is that it will wait until the child process is finish, so my parent daemon process stucks there not doing anything while the time hits midnight. :)

which one do you recommend me to use in this case phil?

thanks alot.

Posted: Mon Oct 09, 2006 4:41 pm
by zoneminder
I would suggest perhaps something using fork and exec. You can have a look at zmdc.pl for examples of how to use them, though your script won't need to be so complicated. There are plenty of other simpler examples on the web and in 'perldoc perltut' I think.

Posted: Tue Oct 10, 2006 1:56 am
by ynn
thank you phil